List of usage examples for android.media RemoteControlClient FLAG_KEY_MEDIA_PREVIOUS
int FLAG_KEY_MEDIA_PREVIOUS
To view the source code for android.media RemoteControlClient FLAG_KEY_MEDIA_PREVIOUS.
Click Source Link
From source file:co.shunya.gita.player.MusicService.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 www . java 2 s .com */ void playNextSong(Long id) { if (id == null || id < 0) { throw new IllegalArgumentException("id must be non nul +ve"); } setState(State.Stopped); relaxResources(false); // release everything except MediaPlayer try { // set the source of the media player to a manual URL or path Track playingItem = mRetriever.getItem(id); createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); if (playingItem == null) { Toast.makeText(this, "All Tracks of current category is been played", Toast.LENGTH_LONG).show(); processStopRequest(true); // stop everything! return; } // BusProvider.getInstance().post(playingItem); mCurrentID = id; mPlayer.setDataSource(playingItem.isDownloded() ? playingItem.getLocalUrl(this) : playingItem.getUrl()); mIsStreaming = playingItem.getUrl().startsWith("http:") || playingItem.getUrl().startsWith("https:"); mSongTitle = playingItem.getTitle(); setState(State.Preparing); updateUI(); setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "Gita") .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, playingItem.getTitle()) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // 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! mPlayer.prepareAsync(); // 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(); } catch (IOException ex) { Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); ex.printStackTrace(); } }
From source file:com.andrew.apollo.MusicPlaybackService.java
/** * Initializes the remote control client *///from w w w. ja va 2 s . c o m private void setUpRemoteControlClient() { final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClient = new RemoteControlClient(PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT)); try { if (mAudioManager != null) { mAudioManager.registerRemoteControlClient(mRemoteControlClient); } } catch (Throwable t) { // seems like this doesn't work on some devices where it requires MODIFY_PHONE_STATE // which is a permission only given to system apps, not third party apps. } // Flags for the media transport control that this client supports. int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP; flags |= RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE; mRemoteControlClient.setOnGetPlaybackPositionListener(this::position); mRemoteControlClient.setPlaybackPositionUpdateListener(this::seek); mRemoteControlClient.setTransportControlFlags(flags); }
From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void registerRemoteControlClient(ComponentName componentName) { audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); Intent remoteControlIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); remoteControlIntent.setComponent(componentName); RemoteControlClient localRemoteControlClient = new RemoteControlClient( PendingIntent.getBroadcast(context, 0, remoteControlIntent, 0)); localRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE); audioManager.registerRemoteControlClient(localRemoteControlClient); this.remoteControlClient = localRemoteControlClient; }
From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java
@SuppressLint("NewApi") public void setUpRemoteControlClient() { if (!Util.isLockScreenEnabled(this)) return;/*from ww w . j a va2s .c om*/ ComponentName componentName = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); if (remoteControlClient == null) { final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(componentName); PendingIntent broadcast = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteControlClient = new RemoteControlClient(broadcast); audioManager.registerRemoteControlClient(remoteControlClient); // Flags for the media transport control that this client supports. int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { flags |= RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE; remoteControlClient .setOnGetPlaybackPositionListener(new RemoteControlClient.OnGetPlaybackPositionListener() { @Override public long onGetPlaybackPosition() { return mediaPlayer.getCurrentPosition(); } }); remoteControlClient.setPlaybackPositionUpdateListener( new RemoteControlClient.OnPlaybackPositionUpdateListener() { @Override public void onPlaybackPositionUpdate(long newPositionMs) { seekTo((int) newPositionMs); } }); } remoteControlClient.setTransportControlFlags(flags); } }
From source file:org.tomahawk.tomahawk_android.services.PlaybackService.java
/** * Update the playback controls/views which are being shown on the lockscreen *//* w ww .ja v a 2 s . co m*/ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateLockscreenControls() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { Log.d(TAG, "updateLockscreenControls()"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat( PendingIntent.getBroadcast(PlaybackService.this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } // Use the remote control APIs (if available) to set the playback state if (isPlaying()) { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED); } int flags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE; if (hasNextEntry()) { flags |= RemoteControlClient.FLAG_KEY_MEDIA_NEXT; } if (hasPreviousEntry()) { flags |= RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS; } mRemoteControlClientCompat.setTransportControlFlags(flags); // Update the remote controls synchronized (this) { RemoteControlClientCompat.MetadataEditorCompat editor = mRemoteControlClientCompat .editMetadata(true); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, getCurrentQuery().getArtist().getPrettyName()) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getCurrentQuery().getArtist().getPrettyName()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentQuery().getPrettyName()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getCurrentQuery().getPreferredTrack().getDuration()); if (!TextUtils.isEmpty(getCurrentQuery().getAlbum().getPrettyName())) { editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getCurrentQuery().getAlbum().getPrettyName()); } editor.apply(); Log.d(TAG, "Setting lockscreen metadata to: " + getCurrentQuery().getArtist().getPrettyName() + ", " + getCurrentQuery().getPrettyName()); } Picasso.with(TomahawkApp.getContext()).cancelRequest(mLockscreenTarget); ImageUtils.loadImageIntoBitmap(TomahawkApp.getContext(), getCurrentQuery().getImage(), mLockscreenTarget, Image.getLargeImageSize(), getCurrentQuery().hasArtistImage()); } }