List of usage examples for android.view KeyEvent KEYCODE_MEDIA_NEXT
int KEYCODE_MEDIA_NEXT
To view the source code for android.view KeyEvent KEYCODE_MEDIA_NEXT.
Click Source Link
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static void linkButtons(Context context, RemoteViews views, boolean playerActive) { Intent intent = new Intent(context, playerActive ? DownloadActivity.class : MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent); views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent); // Emulate media button clicks. intent = new Intent("1"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_play, pendingIntent); intent = new Intent("2"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_next, pendingIntent); intent = new Intent("3"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_previous, pendingIntent); intent = new Intent("4"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_stop, pendingIntent); }
From source file:com.andrew.apolloMod.service.ApolloService.java
/** Return notification remote views * //from w w w .j a v a2s .c o m * @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; }/* www . ja va 2s . 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 processSkipRequest() { if (mPodStatus == podStat.ADVANCEDHACK) { mNowPlaying++;//from w w w . j a va 2 s. co m broadcastMediaButtons(KeyEvent.KEYCODE_MEDIA_NEXT, mAdvancedRemoteApp); return; } if (mState == State.Playing || mState == State.Paused) { mNowPlaying++; 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 w w. j a v a 2 s . co 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(); }