Example usage for org.apache.cordova AudioPlayer getState

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

Introduction

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

Prototype

public int getState() 

Source Link

Document

Get the audio state.

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//  w  w w  .ja  va 2  s.co 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;
}