Example usage for org.apache.cordova AudioPlayer startPlaying

List of usage examples for org.apache.cordova AudioPlayer startPlaying

Introduction

In this page you can find the example usage for org.apache.cordova AudioPlayer startPlaying.

Prototype

public void startPlaying(String file) 

Source Link

Document

Start or resume playing audio file.

Usage

From source file:com.candygram.media.AudioHandler.java

License:Apache License

/**
 * Called when a message is sent to plugin.
 *
 * @param id            The message id//from   w  w  w.  j a v a  2s.c  o m
 * @param data          The message data
 * @return              Object to stop propagation or null
 */
public Object onMessage(String id, Object data) {

    // If phone message
    if (id.equals("telephone")) {

        // If phone ringing, then pause playing
        if ("ringing".equals(data) || "offhook".equals(data)) {

            // Get all audio players and pause them
            for (AudioPlayer audio : this.players.values()) {
                if (audio.getState() == AudioPlayer.STATE.MEDIA_RUNNING.ordinal()) {
                    this.pausedForPhone.add(audio);
                    audio.pausePlaying();
                }
            }

        }

        // If phone idle, then resume playing those players we paused
        else if ("idle".equals(data)) {
            for (AudioPlayer audio : this.pausedForPhone) {
                audio.startPlaying(null);
            }
            this.pausedForPhone.clear();
        }
    }
    return null;
}

From source file:com.candygram.media.AudioHandler.java

License:Apache License

/**
 * Start or resume playing audio file./*w  w w .j  av  a2s .  c om*/
 * @param id            The id of the audio player
 * @param file            The name of the audio file.
 */
public void startPlayingAudio(String id, String file) {
    AudioPlayer audio = getOrCreatePlayer(id, file);
    audio.startPlaying(file);
}