List of usage examples for android.view KeyEvent KEYCODE_MEDIA_PLAY
int KEYCODE_MEDIA_PLAY
To view the source code for android.view KeyEvent KEYCODE_MEDIA_PLAY.
Click Source Link
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();/*www .jav a 2 s .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.miz.mizuu.fragments.MovieDetailsFragment.java
public void onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: playMovie();/* ww w . j a va 2 s.c o m*/ } }
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; }//from w w w . j a va2 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
/** * Starts playing the next song. If manualUrl is null, the next song will be * randomly selected from our Media Retriever (that is, it will be a random * song in the user's device). If manualUrl is non-null, then it specifies * the URL or path to the song that will be played next. *//*from w ww .j a v a 2 s. c om*/ void playNextSong(String manualUrl) { if (mPodStatus == podStat.ADVANCEDHACK) { if ((mNowPlaying == 2 && mPrevPlaying == 1) || (mNowPlaying == 0 && mPrevPlaying == 2) || (mNowPlaying == 1 && mPrevPlaying == 0)) { broadcastMediaButtons(KeyEvent.KEYCODE_MEDIA_NEXT, mAdvancedRemoteApp); } if ((mNowPlaying == 1 && mPrevPlaying == 2) || (mNowPlaying == 0 && mPrevPlaying == 1) || (mNowPlaying == 2 && mPrevPlaying == 0)) { broadcastMediaButtons(KeyEvent.KEYCODE_MEDIA_PREVIOUS, mAdvancedRemoteApp); } if (mNowPlaying == mPrevPlaying && mPrevPlaying == 0) { broadcastMediaButtons(KeyEvent.KEYCODE_MEDIA_PLAY, mAdvancedRemoteApp); } mPrevPlaying = mNowPlaying; return; } mState = State.Stopped; relaxResources(false); // release everything except MediaPlayer MusicRetriever.Track playingItem = null; if (manualUrl != null) { // set the source of the media player to a manual URL or path createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mPlayer.setDataSource(manualUrl); } catch (Exception e) { } mIsStreaming = manualUrl.startsWith("http:") || manualUrl.startsWith("https:"); playingItem = new Track(0, null, manualUrl, null, null, 0); } else { mIsStreaming = false; // playing a locally available song boolean IoErrorFlag = true; while (IoErrorFlag) { if (mNowPlaying >= 0 && mNowPlaying < mRetriever.getCount()) { playingItem = mRetriever.getTrack(mNowPlaying); if (playingItem == null) { mNowPlaying++; } } else { mRetriever.switchToMainPlaylist(); mNowPlaying = 0; return; } // set the source of the media player to a content URI createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mPlayer.setDataSource(getApplicationContext(), playingItem.getURI()); IoErrorFlag = false; } catch (IllegalStateException e) { mPlayer.reset(); } catch (IOException f) { mNowPlaying++; } } } mSongTitle = playingItem.getTitle(); mAlbumArtUri = playingItem.getAlbumArtUri(); mElapsedTime = 0; mState = State.Preparing; setUpAsForeground(mSongTitle + getString(R.string.notify_loading)); // Use the media button APIs (if available) to register ourselves // for media button // events // starts preparing the media player in the background. When it's // done, it will call // our OnPreparedListener (that is, the onPrepared() method on this // class, since we set // the listener to 'this'). // // Until the media player is prepared, we *cannot* call start() on // it! int ioError = 0; while (ioError < 5) { try { mPlayer.prepareAsync(); ioError = 5; } catch (NullPointerException e) { createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mPlayer.setDataSource(getApplicationContext(), playingItem.getURI()); } catch (IllegalStateException e1) { mPlayer.reset(); ioError++; } catch (IOException f) { f.printStackTrace(); ioError = 5; } } catch (IllegalStateException e1) { mPlayer.reset(); ioError++; } } mBanner = getString(R.string.now_playing); localBroadcast(false); // If we are streaming from the internet, we want to hold a Wifi // lock, which prevents // the Wifi radio from going to sleep while the song is playing. If, // on the other hand, // we are *not* streaming, we want to release the lock if we were // holding it before. if (mIsStreaming) mWifiLock.acquire(); else if (mWifiLock.isHeld()) mWifiLock.release(); }