List of usage examples for android.view KeyEvent KEYCODE_MEDIA_PREVIOUS
int KEYCODE_MEDIA_PREVIOUS
To view the source code for android.view KeyEvent KEYCODE_MEDIA_PREVIOUS.
Click Source Link
From source file:com.andrew.apolloMod.service.ApolloService.java
/** Return notification remote views * /*from w w w. j a va 2s . c om*/ * @return [views, bigViews] */ public RemoteViews[] getNotificationViews() { Bitmap b = getAlbumBitmap(); RemoteViews bigViews = new RemoteViews(getPackageName(), R.layout.status_bar_expanded); RemoteViews views = new RemoteViews(getPackageName(), R.layout.status_bar); if (b != null) { bigViews.setImageViewBitmap(R.id.status_bar_album_art, b); views.setViewVisibility(R.id.status_bar_icon, View.GONE); views.setViewVisibility(R.id.status_bar_album_art, View.VISIBLE); views.setImageViewBitmap(R.id.status_bar_album_art, b); } else { views.setViewVisibility(R.id.status_bar_icon, View.VISIBLE); views.setViewVisibility(R.id.status_bar_album_art, View.GONE); } ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.putExtra(CMDNOTIF, 1); mediaButtonIntent.setComponent(rec); KeyEvent mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 2); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 2, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 4); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 4, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); bigViews.setOnClickPendingIntent(R.id.status_bar_prev, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 3); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 3, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent); views.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause); bigViews.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause); views.setTextViewText(R.id.status_bar_track_name, getTrackName()); bigViews.setTextViewText(R.id.status_bar_track_name, getTrackName()); views.setTextViewText(R.id.status_bar_artist_name, getArtistName()); bigViews.setTextViewText(R.id.status_bar_artist_name, getArtistName()); bigViews.setTextViewText(R.id.status_bar_album_name, getAlbumName()); return new RemoteViews[] { views, bigViews }; }
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 ava2 s. co 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 processSkipRwdRequest() { if (mPodStatus == podStat.ADVANCEDHACK) { mNowPlaying--;//from w w w .j a v a 2s .c o m broadcastMediaButtons(KeyEvent.KEYCODE_MEDIA_PREVIOUS, mAdvancedRemoteApp); return; } if (mState == State.Playing || mState == State.Paused) { mNowPlaying--; if (mNowPlaying < 0) mNowPlaying = -1; tryToGetAudioFocus(); playNextSong(null); } }
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 av a 2 s.c o m 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(); }