リモートコントロールを表示するにはAudioFocusを取得する必要があります。
省略されているのは、それくらい常識って事なんでしょうか。
ComponentName myEventReceiver = new ComponentName(getPackageName(), MusicIntentReciever.class.getName());
AudioManager myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
myAudioManager.registerMediaButtonEventReceiver(myEventReceiver);
myAudioManager.requestAudioFocus( new OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
Log.d(TAG, "focusChanged:"+focusChange );
}
} , AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
// build the PendingIntent for the remote control client
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(myEventReceiver);
PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
// create and register the remote control client
mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
myAudioManager.registerRemoteControlClient(mRemoteControlClient);
mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
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);
mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
mRemoteControlClient.editMetadata(true)
.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, "a")
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "b")
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, "c")
.apply();
MusicIntentRecieverはAndroid SDKのサンプルのRandomMusicPlayerに含まれているものが使えます。そちらを参考にして下さい。
0 件のコメント:
コメントを投稿