Java Code Examples for android.view.KeyEvent#KEYCODE_MEDIA_PAUSE
The following examples show how to use
android.view.KeyEvent#KEYCODE_MEDIA_PAUSE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaButtonIntentReceiver.java From HaoReader with GNU General Public License v3.0 | 6 votes |
public static boolean handleIntent(final Intent intent) { if (DEBUG) Log.d(TAG, "Received intent: " + intent); final String intentAction = intent.getAction(); if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return false; } final int keycode = event.getKeyCode(); final int action = event.getAction(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = ReadAloudService.ActionMediaButton; break; default: break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { RxBus.get().post(RxBusTag.MEDIA_BUTTON, command); return true; } } } return false; }
Example 2
Source File: MediaButtonIntentReceiver.java From webTube with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { return; } KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); Log.i("Key", event.getKeyCode() + " pressed"); int action = event.getAction(); if (action == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PAUSE || event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || event.getKeyCode() == 79) { try { MainActivity.toggleVideo(); } catch (Exception e) { // Activity is not running e.printStackTrace(); } } } }
Example 3
Source File: VideoView.java From Vitamio with Apache License 2.0 | 5 votes |
@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_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 || keyCode == KeyEvent.KEYCODE_SPACE) { if (mMediaPlayer.isPlaying()) { pause(); 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); }
Example 4
Source File: VideoView.java From react-native-android-vitamio with MIT License | 5 votes |
@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_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 || keyCode == KeyEvent.KEYCODE_SPACE) { if (mMediaPlayer.isPlaying()) { pause(); 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); }
Example 5
Source File: MediaButtonIntentReceiver.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
public static boolean handleIntent(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return false; } final int keycode = event.getKeyCode(); final int action = event.getAction(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = ReadAloudService.ActionMediaPlay; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = ReadAloudService.ActionMediaPrev; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = ReadAloudService.ActionMediaNext; break; default: break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { readAloud(context, command); return true; } } } return false; }
Example 6
Source File: ExoVideoPlaybackControlView.java From ExoVideoView with Apache License 2.0 | 5 votes |
@SuppressLint("InlinedApi") private static boolean isHandledMediaKey(int keyCode) { return keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD || keyCode == KeyEvent.KEYCODE_MEDIA_REWIND || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE || keyCode == KeyEvent.KEYCODE_MEDIA_NEXT || keyCode == KeyEvent.KEYCODE_MEDIA_PREVIOUS; }
Example 7
Source File: IjkVideoView.java From talk-android with MIT License | 5 votes |
@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(); 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); }
Example 8
Source File: MediaControlView.java From Cirrus_depricated with GNU General Public License v2.0 | 5 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN; if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE) { if (uniqueDown) { doPauseResume(); //show(sDefaultTimeout); if (mPauseButton != null) { mPauseButton.requestFocus(); } } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (uniqueDown && !mPlayer.isPlaying()) { mPlayer.start(); updatePausePlay(); //show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (uniqueDown && mPlayer.isPlaying()) { mPlayer.pause(); updatePausePlay(); //show(sDefaultTimeout); } return true; } //show(sDefaultTimeout); return super.dispatchKeyEvent(event); }
Example 9
Source File: MediaButtonIntentReceiver.java From a with GNU General Public License v3.0 | 5 votes |
public static boolean handleIntent(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return false; } final int keycode = event.getKeyCode(); final int action = event.getAction(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = ReadAloudService.ActionMediaButton; break; default: break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { readAloud(context, command); return true; } } } return false; }
Example 10
Source File: CustomizeControlView.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@SuppressLint("InlinedApi") private static boolean isHandledMediaKey(int keyCode) { return keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD || keyCode == KeyEvent.KEYCODE_MEDIA_REWIND || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE || keyCode == KeyEvent.KEYCODE_MEDIA_NEXT || keyCode == KeyEvent.KEYCODE_MEDIA_PREVIOUS; }
Example 11
Source File: CustomizeControlView.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public boolean dispatchMediaKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); if (player == null || !isHandledMediaKey(keyCode)) { return false; } if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { fastForward(); } else if (keyCode == KeyEvent.KEYCODE_MEDIA_REWIND) { rewind(); } else if (event.getRepeatCount() == 0) { switch (keyCode) { case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: controlDispatcher.dispatchSetPlayWhenReady(player, !player.getPlayWhenReady()); break; case KeyEvent.KEYCODE_MEDIA_PLAY: controlDispatcher.dispatchSetPlayWhenReady(player, true); break; case KeyEvent.KEYCODE_MEDIA_PAUSE: controlDispatcher.dispatchSetPlayWhenReady(player, false); break; case KeyEvent.KEYCODE_MEDIA_NEXT: next(); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: previous(); break; default: break; } } } return true; }
Example 12
Source File: MediaButtonIntentReceiver.java From VinylMusicPlayer with GNU General Public License v3.0 | 4 votes |
public static boolean handleIntent(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return false; } final int keycode = event.getKeyCode(); final int action = event.getAction(); final long eventTime = event.getEventTime() != 0 ? event.getEventTime() : System.currentTimeMillis(); // Fallback to system time if event time was not available. String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: command = MusicService.ACTION_STOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MusicService.ACTION_TOGGLE_PAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MusicService.ACTION_SKIP; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MusicService.ACTION_REWIND; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MusicService.ACTION_PAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MusicService.ACTION_PLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (event.getRepeatCount() == 0) { // Only consider the first event in a sequence, not the repeat events, // so that we don't trigger in cases where the first event went to // a different app (e.g. when the user ends a phone call by // long pressing the headset button) // The service may or may not be running, but we need to send it // a command. if (keycode == KeyEvent.KEYCODE_HEADSETHOOK || keycode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (eventTime - mLastClickTime >= DOUBLE_CLICK) { mClickCounter = 0; } mClickCounter++; if (DEBUG) Log.v(TAG, "Got headset click, count = " + mClickCounter); mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT); Message msg = mHandler.obtainMessage( MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context); long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0; if (mClickCounter >= 3) { mClickCounter = 0; } mLastClickTime = eventTime; acquireWakeLockAndSendMessage(context, msg, delay); } else { startService(context, command); } return true; } } } } return false; }
Example 13
Source File: MusicPlayerReceiver.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) { if (intent.getExtras() == null) { return; } KeyEvent keyEvent = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT); if (keyEvent == null) { return; } if (keyEvent.getAction() != KeyEvent.ACTION_DOWN) return; switch (keyEvent.getKeyCode()) { case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: if (MediaController.getInstance().isMessagePaused()) { MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject()); } else { MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject()); } break; case KeyEvent.KEYCODE_MEDIA_PLAY: MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject()); break; case KeyEvent.KEYCODE_MEDIA_PAUSE: MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject()); break; case KeyEvent.KEYCODE_MEDIA_STOP: break; case KeyEvent.KEYCODE_MEDIA_NEXT: MediaController.getInstance().playNextMessage(); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: MediaController.getInstance().playPreviousMessage(); break; } } else { if (intent.getAction().equals(MusicPlayerService.NOTIFY_PLAY)) { MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject()); } else if (intent.getAction().equals(MusicPlayerService.NOTIFY_PAUSE) || intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject()); } else if (intent.getAction().equals(MusicPlayerService.NOTIFY_NEXT)) { MediaController.getInstance().playNextMessage(); } else if (intent.getAction().equals(MusicPlayerService.NOTIFY_CLOSE)) { MediaController.getInstance().cleanupPlayer(true, true); } else if (intent.getAction().equals(MusicPlayerService.NOTIFY_PREVIOUS)) { MediaController.getInstance().playPreviousMessage(); } } }
Example 14
Source File: VideoPlayerActivity.java From VCL-Android with Apache License 2.0 | 4 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_BUTTON_B) return super.onKeyDown(keyCode, event); if (mIsLoading) { switch (keyCode) { case KeyEvent.KEYCODE_S: case KeyEvent.KEYCODE_MEDIA_STOP: exitOK(); return true; } return false; } showOverlayTimeout(OVERLAY_TIMEOUT); switch (keyCode) { case KeyEvent.KEYCODE_F: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: case KeyEvent.KEYCODE_MEDIA_NEXT: seekDelta(10000); return true; case KeyEvent.KEYCODE_R: case KeyEvent.KEYCODE_MEDIA_REWIND: case KeyEvent.KEYCODE_MEDIA_PREVIOUS: seekDelta(-10000); return true; case KeyEvent.KEYCODE_BUTTON_R1: seekDelta(60000); return true; case KeyEvent.KEYCODE_BUTTON_L1: seekDelta(-60000); return true; case KeyEvent.KEYCODE_BUTTON_A: if (mOverlayProgress.getVisibility() == View.VISIBLE) return false; case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_SPACE: if (mIsNavMenu) return navigateDvdMenu(keyCode); else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) //prevent conflict with remote control return super.onKeyDown(keyCode, event); else doPlayPause(); return true; case KeyEvent.KEYCODE_O: case KeyEvent.KEYCODE_BUTTON_Y: case KeyEvent.KEYCODE_MENU: showAdvancedOptions(mAdvOptions); return true; case KeyEvent.KEYCODE_V: case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: case KeyEvent.KEYCODE_BUTTON_X: onAudioSubClick(mTracks); return true; case KeyEvent.KEYCODE_N: showNavMenu(); return true; case KeyEvent.KEYCODE_A: resizeVideo(); return true; case KeyEvent.KEYCODE_M: case KeyEvent.KEYCODE_VOLUME_MUTE: updateMute(); return true; case KeyEvent.KEYCODE_S: case KeyEvent.KEYCODE_MEDIA_STOP: exitOK(); return true; case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (mIsNavMenu) return navigateDvdMenu(keyCode); else return super.onKeyDown(keyCode, event); case KeyEvent.KEYCODE_J: delayAudio(-50000l); return true; case KeyEvent.KEYCODE_K: delayAudio(50000l); return true; case KeyEvent.KEYCODE_G: delaySubs(-50000l); return true; case KeyEvent.KEYCODE_H: delaySubs(50000l); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_UP: if (mMute) { updateMute(); return true; } else return false; } return super.onKeyDown(keyCode, event); }
Example 15
Source File: MediaButtonReceiver.java From AssistantBySDK with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { //获取对应Acton,判断是否是需要的ACTION_MEDIA_BUTTON /*if(VoiceService.get().getAwakener().isWorking()){ return; }*/ this.mContext=context; String action = intent.getAction(); Log.e(TAG, "onReceive:"+action+",context="+context); if(action.equalsIgnoreCase("android.media.AUDIO_BECOMING_NOISY")){ Intent it=new Intent(this.mContext,AssistantService.class); it.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.PAUSE_PLAY); this.mContext.startService(it); } else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)){ KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) return; if (event.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK && event.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE && event.getAction() != KeyEvent.ACTION_DOWN) return; if(!eventLock.tryLock())return; try{ switch (event.getKeyCode()){ case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: //Log.e(TAG, "KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE"); long time = SystemClock.uptimeMillis(); switch (event.getAction()){ case KeyEvent.ACTION_DOWN: //Log.e(TAG, "KeyEvent.ACTION_DOWN,count="+event.getRepeatCount()); if (event.getRepeatCount() > 0) break; mHeadsetDownTime = time; break; case KeyEvent.ACTION_UP: //Log.e(TAG, "KeyEvent.ACTION_UP,count="+event.getRepeatCount()); long t=(time-mHeadsetUpTime); mHeadsetUpTime = time; if (time - mHeadsetDownTime >= 1000){ longClick(); clicks.set(0); break; } else if(clicks.get()!=0&&t<timeout){ clicks.incrementAndGet(); eventCondition.signal(); } else if(clicks.get()==0){ clicks.incrementAndGet(); new EventAsynTask().execute(); } break; } break; case KeyEvent.KEYCODE_MEDIA_PLAY: Log.e(TAG, "KeyEvent.KEYCODE_MEDIA_PLAY"); click(); break; case KeyEvent.KEYCODE_MEDIA_PAUSE: Log.e(TAG, "KeyEvent.KEYCODE_MEDIA_PAUSE"); click(); break; case KeyEvent.KEYCODE_MEDIA_STOP: Log.e(TAG, "KeyEvent.KEYCODE_MEDIA_STOP"); click(); break; case KeyEvent.KEYCODE_MEDIA_NEXT: Log.e(TAG, "KeyEvent.KEYCODE_MEDIA_NEXT"); doubleClick(); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: Log.e(TAG, "KeyEvent.KEYCODE_MEDIA_PREVIOUS"); trebleClick(); break; } if (isOrderedBroadcast()){ Log.e(TAG, "isOrderedBroadcast"); abortBroadcast(); } }finally{ eventLock.unlock(); } } }
Example 16
Source File: PlaybackService.java From AntennaPodSP with MIT License | 4 votes |
/** * Handles media button events */ private void handleKeycode(int keycode) { if (AppConfig.DEBUG) Log.d(TAG, "Handling keycode: " + keycode); final PlayerStatus status = mediaPlayer.getPSMPInfo().playerStatus; switch (keycode) { case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: if (status == PlayerStatus.PLAYING) { mediaPlayer.pause(true, true); } else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) { mediaPlayer.resume(); } else if (status == PlayerStatus.PREPARING) { mediaPlayer.setStartWhenPrepared(!mediaPlayer.isStartWhenPrepared()); } else if (status == PlayerStatus.INITIALIZED) { mediaPlayer.setStartWhenPrepared(true); mediaPlayer.prepare(); } break; case KeyEvent.KEYCODE_MEDIA_PLAY: if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) { mediaPlayer.resume(); } else if (status == PlayerStatus.INITIALIZED) { mediaPlayer.setStartWhenPrepared(true); mediaPlayer.prepare(); } break; case KeyEvent.KEYCODE_MEDIA_PAUSE: if (status == PlayerStatus.PLAYING) { mediaPlayer.pause(true, true); } break; case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { mediaPlayer.seekDelta(PlaybackController.DEFAULT_SEEK_DELTA); break; } case KeyEvent.KEYCODE_MEDIA_REWIND: { mediaPlayer.seekDelta(-PlaybackController.DEFAULT_SEEK_DELTA); break; } } }
Example 17
Source File: VideoControllerView.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (mPlayer == null) { return true; } int keyCode = event.getKeyCode(); final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN; if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE) { if (uniqueDown) { doPauseResume(); show(sDefaultTimeout); if (mPauseButton != null) { mPauseButton.requestFocus(); } } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (uniqueDown && !mPlayer.isMediaPlayerPlaying()) { mPlayer.mediaPlayerStart(); updatePausePlay(); show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (uniqueDown && mPlayer.isMediaPlayerPlaying()) { mPlayer.mediaPlayerPause(); updatePausePlay(); show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { // don't show the controls for volume adjustment return super.dispatchKeyEvent(event); } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) { if (uniqueDown) { hide(); } return true; } show(sDefaultTimeout); return super.dispatchKeyEvent(event); }
Example 18
Source File: KSYVideoView.java From KSYMediaPlayer_Android with Apache License 2.0 | 4 votes |
@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 (ksyMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } else { start(); mMediaController.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (!ksyMediaPlayer.isPlaying()) { start(); mMediaController.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (ksyMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } return true; } else { toggleMediaControlsVisiblity(); } } return super.onKeyDown(keyCode, event); }
Example 19
Source File: MediaController.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN; if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE) { if (uniqueDown) { doPauseResume(); show(sDefaultTimeout); if (mPauseButton != null) { mPauseButton.requestFocus(); } } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (uniqueDown && !mPlayer.isPlaying()) { mPlayer.start(); updatePausePlay(); show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (uniqueDown && mPlayer.isPlaying()) { mPlayer.pause(); updatePausePlay(); show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE || keyCode == KeyEvent.KEYCODE_CAMERA) { // don't show the controls for volume adjustment return super.dispatchKeyEvent(event); } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) { if (uniqueDown) { hide(); } return true; } show(sDefaultTimeout); return super.dispatchKeyEvent(event); }
Example 20
Source File: AudioPlayerActivity.java From VCL-Android with Apache License 2.0 | 4 votes |
public boolean onKeyDown(int keyCode, KeyEvent event){ switch (keyCode){ /* * Playback control */ case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_SPACE: togglePlayPause(); return true; case KeyEvent.KEYCODE_MEDIA_STOP: mService.stop(); finish(); return true; case KeyEvent.KEYCODE_F: case KeyEvent.KEYCODE_BUTTON_R1: goNext(); return true; case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: seek(10000); return true; case KeyEvent.KEYCODE_MEDIA_REWIND: seek(-10000); return true; case KeyEvent.KEYCODE_R: case KeyEvent.KEYCODE_BUTTON_L1: goPrevious(); return true; /* * Playlist navigation */ case KeyEvent.KEYCODE_DPAD_UP: selectPrevious(); mRecyclerView.requestFocus(); return true; case KeyEvent.KEYCODE_DPAD_DOWN: selectNext(); mRecyclerView.requestFocus(); return true; case KeyEvent.KEYCODE_DPAD_CENTER: if (mRecyclerView.hasFocus()) { playSelection(); return true; } else return false; default: return super.onKeyDown(keyCode, event); } }