@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void setUpRemoteControlClient() { //Legacy for ICS if (mRemoteControlClient == null) { Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mMediaButtonReceiverComponent); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); // create and register the remote control client mRemoteControlClient = new RemoteControlClient(mediaPendingIntent); mAudioManager.registerRemoteControlClient(mRemoteControlClient); } mRemoteControlClient.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP); }
public void refreshState(boolean playing, long position, int transportControls) { if (mRemoteControl != null) { mRemoteControl.setPlaybackState(playing ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_STOPPED, position, playing ? 1 : 0); mRemoteControl.setTransportControlFlags(transportControls); } }
/** * Perform initialization required for RemoteControlClient. */ public void initializeRemote() { // make sure there is only one registered remote unregisterRemote(); if (MediaButtonReceiver.useHeadsetControls(mContext) == false) return; // Receive 'background' play button events AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); ComponentName receiver = new ComponentName(mContext.getPackageName(), MediaButtonReceiver.class.getName()); audioManager.registerMediaButtonEventReceiver(receiver); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(new ComponentName(mContext.getPackageName(), MediaButtonReceiver.class.getName())); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(mContext, 0, mediaButtonIntent, 0); RemoteControlClient remote = new RemoteControlClient(mediaPendingIntent); // Things we can do (eg: buttons to display on lock screen) int flags = RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE; remote.setTransportControlFlags(flags); audioManager.registerRemoteControlClient(remote); mRemote = remote; }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) void registerRemoteControl(ComponentName rcvMedia) { mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(rcvMedia); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0); remoteControlClient = new RemoteControlClient(mediaPendingIntent); remoteControlClient.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS ); mAudioManager.registerRemoteControlClient(remoteControlClient); }
| RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD | RemoteControlClient.FLAG_KEY_MEDIA_REWIND; mRemoteControlClient.setTransportControlFlags(flags); mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); Bitmap AlbumArt=BitmapFactory.decodeResource(getResources(), R.drawable.alislahthumbmain); mIslahReceiverComponent=new ComponentName(this,AlIslahReceiver.class.getName()); audioManager.registerMediaButtonEventReceiver(mIslahReceiverComponent); Intent mediaButtonIntent=new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mIslahReceiverComponent); PendingIntent mediaPendingIntent=PendingIntent.getBroadcast(getApplicationContext(), 0,mediaButtonIntent,0); RemoteControlClient mRemoteControlClient=new RemoteControlClient(mediaPendingIntent); mRemoteControlClient.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE,AlIslahApplication.getStreamTitle()) .putBitmap(100,AlbumArt) .apply(); mRemoteControlClient.setPlaybackState( RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClient.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE| RemoteControlClient.FLAG_KEY_MEDIA_STOP); audioManager.registerRemoteControlClient(mRemoteControlClient);
audioManager.registerRemoteControlClient(remoteControlClient); remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT);
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) void updateRemoteControl() { updateRemoteControlState(RemoteControlClient.PLAYSTATE_PLAYING); remoteControlClient.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
private void unregisterRemoteControlClient() { // Unregister the RCC with AudioManager and MediaRouter if (mRemoteControlClient != null) { mRemoteControlClient.setTransportControlFlags(0); mAudioManager.abandonAudioFocus(mAfChangeListener); mAudioManager.unregisterMediaButtonEventReceiver(mEventReceiver); mAudioManager.unregisterRemoteControlClient(mRemoteControlClient); mMediaRouter.removeRemoteControlClient(mRemoteControlClient); SampleMediaButtonReceiver.setActivity(null); mRemoteControlClient = null; } }
remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT); audioManager.registerRemoteControlClient(remoteControlClient);
private void registerRemoteControlClient() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // Create the RCC and register with AudioManager and MediaRouter mAudioManager.requestAudioFocus(mAfChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); mAudioManager.registerMediaButtonEventReceiver(mEventReceiver); mRemoteControlClient = new RemoteControlClient(mMediaPendingIntent); mAudioManager.registerRemoteControlClient(mRemoteControlClient); mMediaRouter.addRemoteControlClient(mRemoteControlClient); SampleMediaButtonReceiver.setActivity(MainActivity.this); mRemoteControlClient.setTransportControlFlags(RemoteControlClient .FLAG_KEY_MEDIA_PLAY_PAUSE); mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } }