Example usage for android.view KeyEvent KEYCODE_MEDIA_PAUSE

List of usage examples for android.view KeyEvent KEYCODE_MEDIA_PAUSE

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_MEDIA_PAUSE.

Prototype

int KEYCODE_MEDIA_PAUSE

To view the source code for android.view KeyEvent KEYCODE_MEDIA_PAUSE.

Click Source Link

Document

Key code constant: Pause media key.

Usage

From source file:com.android.tv.ui.TvOverlayManager.java

/**
 * Checks whether the given {@code keyCode} can start the system's music app or not.
 *//*w  w w . java  2 s  . co m*/
private static boolean isMediaStartKey(int keyCode) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
    case KeyEvent.KEYCODE_MEDIA_PLAY:
    case KeyEvent.KEYCODE_MEDIA_PAUSE:
    case KeyEvent.KEYCODE_MEDIA_NEXT:
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
    case KeyEvent.KEYCODE_MEDIA_REWIND:
    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
        return true;
    }
    return false;
}

From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
            && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();//from  ww  w .  jav a 2s  .c  om
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisibility();
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.xnxs.mediaplayer.widget.media.VRVideoView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
            && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();//from   ww  w. ja v  a 2s.  c  o  m
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    }
    return super.onKeyDown(keyCode, event);
}

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

public boolean dispatchMediaKeyEvent(KeyEvent event) {

    int action = event.getAction();
    int keyCode = event.getKeyCode();

    if (audioManager.isMusicActive() && !ttsIsRunning()) {
        return false;
    }/*  w  w  w. ja  v a2 s.  c  o m*/

    switch (keyCode) {

    case KeyEvent.KEYCODE_MEDIA_PLAY:
    case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
    case KeyEvent.KEYCODE_MEDIA_PAUSE:
        return simulateButtonPress(action, R.id.playPauseButton, playPauseButton);

    case KeyEvent.KEYCODE_MEDIA_STOP:
        return simulateButtonPress(action, R.id.stopButton, stopButton);

    case KeyEvent.KEYCODE_MEDIA_NEXT:
        return simulateButtonPress(action, R.id.nextButton, nextButton);

    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        return simulateButtonPress(action, R.id.prevButton, prevButton);
    }

    return false;
}

From source file:me.spadival.podmode.PodModeService.java

void processPauseRequest() {
    if (mPodStatus == podStat.ADVANCEDHACK) {
        broadcastMediaButtons(KeyEvent.KEYCODE_MEDIA_PAUSE, mAdvancedRemoteApp);
        return;// w  w w.j a  v a 2  s  .c o m
    }

    if (mState == State.Retrieving) {
        // If we are still retrieving media, clear the flag that indicates
        // we should start
        // playing when we're ready
        mStartPlayingAfterRetrieve = false;
        return;
    }

    if (mState == State.Playing) {
        // Pause media player and cancel the 'foreground service' state.
        mState = State.Paused;
        mPlayer.pause();
        relaxResources(false); // while paused, we always retain the
        // MediaPlayer
        // do not give up audio focus
    }

}