Example usage for android.media MediaPlayer pause

List of usage examples for android.media MediaPlayer pause

Introduction

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

Prototype

public void pause() throws IllegalStateException 

Source Link

Document

Pauses playback.

Usage

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

public void onMediaButtonEvent(int buttonId) {

    if (buttonId == R.id.playPauseButton && !ttsIsRunning()) {
        startTextToSpeech();//from   ww w .  j a  va 2 s .c om
        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;
    }
}