Example usage for com.google.gwt.dom.client MediaElement CAN_PLAY_PROBABLY

List of usage examples for com.google.gwt.dom.client MediaElement CAN_PLAY_PROBABLY

Introduction

In this page you can find the example usage for com.google.gwt.dom.client MediaElement CAN_PLAY_PROBABLY.

Prototype

String CAN_PLAY_PROBABLY

To view the source code for com.google.gwt.dom.client MediaElement CAN_PLAY_PROBABLY.

Click Source Link

Document

Constant returned from #canPlayType(String) .

Usage

From source file:es.deusto.weblab.client.ui.audio.AudioManager.java

License:Open Source License

/**
 * Helper method which will play a sound if certain conditions are met:
 * Sound is enabled./*  w w  w .  j av  a 2  s.co  m*/
 * Sound is supported.
 * If they are not, calling this method will have no effect.
 * 
 * The file type is inferred by the web browser. If it supports OGG, it will use the ".ogg" extension. If it doesn't, but it
 * supports MP3, it will use ".mp3". It will also try WAV, and otherwise it will not work. Therefore, the audio files must be 
 * duplicated in these three formats to work. 
 * 
 * @param file File to play. The path should be relative to the module base URL. E.g. "/audio/foo" will select foo.ogg, foo.mp3 or foo.wav
 * 
 * @return AudioElement being played, or null. May be used to modify the default behaviour, such
 * as enabling loop mode.
 */
public AudioElement playBest(String file) {
    if (this.getSoundEnabled()) {
        final Audio audio = Audio.createIfSupported();
        if (audio != null) {
            final AudioElement elem = audio.getAudioElement();

            // First try probably
            if (elem.canPlayType(OGG_TYPE).equals(MediaElement.CAN_PLAY_PROBABLY))
                elem.setSrc(GWT.getModuleBaseURL() + file + ".ogg");
            else if (elem.canPlayType(MP3_TYPE).equals(MediaElement.CAN_PLAY_PROBABLY))
                elem.setSrc(GWT.getModuleBaseURL() + file + ".mp3");
            else if (elem.canPlayType(WAV_TYPE).equals(MediaElement.CAN_PLAY_PROBABLY))
                elem.setSrc(GWT.getModuleBaseURL() + file + ".wav");
            // Then maybe
            else if (elem.canPlayType(OGG_TYPE).equals(MediaElement.CAN_PLAY_MAYBE))
                elem.setSrc(GWT.getModuleBaseURL() + file + ".ogg");
            else if (elem.canPlayType(MP3_TYPE).equals(MediaElement.CAN_PLAY_MAYBE))
                elem.setSrc(GWT.getModuleBaseURL() + file + ".mp3");
            else if (elem.canPlayType(WAV_TYPE).equals(MediaElement.CAN_PLAY_MAYBE))
                elem.setSrc(GWT.getModuleBaseURL() + file + ".wav");
            // Then fail
            else
                return null;

            elem.play();
            return elem;
        }
    }
    return null;
}

From source file:net.cbtltd.client.field.MediaControl.java

/**
 * Sets the ID of an audio object.//ww  w .j  a  va 2 s.com
 *
 * @param value the new ID of the audio object.
 */
public void setAudioValue(String value) {
    Log.debug("setAudioValue " + value);
    try {
        this.value = value;
        if (media == null || value == null || value.isEmpty()) {
            return;
        }

        else if (MediaElement.CAN_PLAY_PROBABLY.equals(media.canPlayType(AudioElement.TYPE_WAV))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.AUDIO_DIRECTORY + value + Text.AUDIO_WAV);
        } else if (MediaElement.CAN_PLAY_PROBABLY.equals(media.canPlayType(AudioElement.TYPE_MP3))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.AUDIO_DIRECTORY + value + Text.AUDIO_MP3);
        } else if (MediaElement.CAN_PLAY_PROBABLY.equals(media.canPlayType(AudioElement.TYPE_OGG))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.AUDIO_DIRECTORY + value + Text.AUDIO_OGG);
        }

        else if (MediaElement.CAN_PLAY_MAYBE.equals(media.canPlayType(AudioElement.TYPE_WAV))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.AUDIO_DIRECTORY + value + Text.AUDIO_WAV);
        } else if (MediaElement.CAN_PLAY_MAYBE.equals(media.canPlayType(AudioElement.TYPE_MP3))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.AUDIO_DIRECTORY + value + Text.AUDIO_MP3);
        } else if (MediaElement.CAN_PLAY_MAYBE.equals(media.canPlayType(AudioElement.TYPE_OGG))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.AUDIO_DIRECTORY + value + Text.AUDIO_OGG);
        } else {
            return;
        }

        media.load();
        //media.setPreload(MediaElement.PRELOAD_AUTO);
        Log.debug("loaded " + value);
    } catch (Exception x) {
        Log.error(
                "setAudioValue " + HOSTS.rootUrl() + HasUrls.AUDIO_DIRECTORY + value + "\n" + media.getError());
    }
}

From source file:net.cbtltd.client.field.MediaControl.java

/**
 * Sets the ID of a video object./*w  w  w  . ja v  a 2 s .c o  m*/
 *
 * @param value the new ID of the video object.
 */
public void setVideoValue(String value) {
    Log.debug("setVideoValue " + value);
    try {
        this.value = value;
        if (media == null || value == null || value.isEmpty()) {
            return;
        }

        else if (MediaElement.CAN_PLAY_PROBABLY.equals(media.canPlayType(VideoElement.TYPE_MP4))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.VIDEO_DIRECTORY + value + Text.VIDEO_MP4);
        } else if (MediaElement.CAN_PLAY_PROBABLY.equals(media.canPlayType(VideoElement.TYPE_OGG))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.VIDEO_DIRECTORY + value + Text.VIDEO_OGG);
        } else if (MediaElement.CAN_PLAY_PROBABLY.equals(media.canPlayType(VideoElement.TYPE_WEBM))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.VIDEO_DIRECTORY + value + Text.VIDEO_WEBM);
        }

        else if (MediaElement.CAN_PLAY_MAYBE.equals(media.canPlayType(VideoElement.TYPE_MP4))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.VIDEO_DIRECTORY + value + Text.VIDEO_MP4);
        } else if (MediaElement.CAN_PLAY_MAYBE.equals(media.canPlayType(VideoElement.TYPE_OGG))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.VIDEO_DIRECTORY + value + Text.VIDEO_OGG);
        } else if (MediaElement.CAN_PLAY_MAYBE.equals(media.canPlayType(VideoElement.TYPE_WEBM))) {
            media.setSrc(HOSTS.rootUrl() + HasUrls.VIDEO_DIRECTORY + value + Text.VIDEO_WEBM);
        } else {
            return;
        }
        media.load();
        //media.setPreload(MediaElement.PRELOAD_AUTO);
        Log.debug("loaded " + value);
    } catch (Exception x) {
        Log.error("setVideoValue " + HOSTS.rootUrl() + HasUrls.AUDIO_DIRECTORY + value);
    }
}