Example usage for android.media MediaPlayer isPlaying

List of usage examples for android.media MediaPlayer isPlaying

Introduction

In this page you can find the example usage for android.media MediaPlayer isPlaying.

Prototype

public native boolean isPlaying();

Source Link

Document

Checks whether the MediaPlayer is playing.

Usage

From source file:com.sourceauditor.sahomemonitor.MainActivity.java

@Override
public void onPrepared(MediaPlayer mp) {
    if (!mp.isPlaying() && !pauseBeforePlaying) {
        try {//from   ww  w . j  av  a2  s  .c  o  m
            mp.start();
            this.playPauseButton.setText(getString(R.string.label_pause));
        } catch (Exception e) {
            Log.e(TAG, "Error trying to start media player: " + e.getMessage());
        }
    }
}

From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java

protected void stopAndReleasePlayer(MediaPlayer player) {
    //TODO need to release looping background metadata task here somehow too
    if (LOCAL_LOGV)
        log("stopAndReleasePlayer()", "v");
    if (player != null) {
        try {//from  w  w w  .j  a  v  a2 s.c  o  m
            if (player.isPlaying()) {
                player.stop();
                if (LOCAL_LOGV)
                    log("stopped mediaPlayer", "v");
            }
            if (LOCAL_LOGV)
                log("mediaPlayer not playing", "v");
        } catch (IllegalStateException e) {
            if (LOCAL_LOGV)
                log("player in wrong state to stop", "v");
        }
        try {
            player.reset();
            if (LOCAL_LOGV)
                log("reset mediaPlayer", "v");
        } catch (IllegalStateException e) {
            if (LOCAL_LOGV)
                log("player in wrong state to reset", "v");
        }
        player.release();
    }
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

public void onMediaButtonEvent(int buttonId) {

    if (buttonId == R.id.playPauseButton && !ttsIsRunning()) {
        startTextToSpeech();//  w w  w .ja  v  a 2  s.  c o  m
        return;
    }

    TTSPlaybackItem item = this.ttsPlaybackItemQueue.peek();

    if (item == null) {
        stopTextToSpeech(false);
        return;
    }

    MediaPlayer mediaPlayer = item.getMediaPlayer();
    uiHandler.removeCallbacks(progressBarUpdater);

    switch (buttonId) {
    case R.id.stopButton:
        stopTextToSpeech(true);
        return;
    case R.id.nextButton:
        performSkip(true);
        uiHandler.post(progressBarUpdater);
        return;
    case R.id.prevButton:
        performSkip(false);
        uiHandler.post(progressBarUpdater);
        return;

    case R.id.playPauseButton:
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.pause();
        } else {
            mediaPlayer.start();
            uiHandler.post(progressBarUpdater);
        }
        return;
    }
}