有没有人得到这项工作? MediaSessionCallback中没有任何事件被调用.
以下是媒体会话的初始化方式
mSession = new MediaSessionCompat(this,TAG); mSession.setCallback(new MediaSessionCallback()); mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_buttonS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTRolS); mSession.setPlaybackTolocal(AudioManager.STREAM_MUSIC); mSession.setActive(true);
以下是设置元数据的方式
MediaMetadataCompat.Builder MetadataBuilder = new MediaMetadataCompat.Builder(); MetadataBuilder .putLong(MediaMetadata.MetaDATA_KEY_DURATION,clip.getDuration()) .putString(MediaMetadata.MetaDATA_KEY_MEDIA_ID,clip.getClipID()) .putString(MediaMetadata.MetaDATA_KEY_Title,clip.getTitle()) .putString(MediaMetadata.MetaDATA_KEY_ARTIST,clip.getSourcename()) .putString(MediaMetadata.MetaDATA_KEY_ALBUM_ART_URI,clip.getimageUrl()) .putLong(MediaMetadata.MetaDATA_KEY_DURATION,clip.getDuration()); mSession.setMetadata(MetadataBuilder.build());
最后,通知代码:
MediaSession mediaSession = (MediaSession) session.getMediaSession(); Notification.Builder builder = new Notification.Builder(c) .setDefaults(0) .setSmallicon(R.drawable.ic_notif) .setVisibility(NotificationCompat.VISIBIliTY_PUBliC) .setContentTitle(clip.getTitle()) .setContentText(clip.getSourcename()) .setProgress((int)duration,(int)progress,false) .setWhen(0) .setContentIntent(pendingIntent); if (playing) { builder.addAction(R.drawable.ic_media_pause,c.getString(R.string.media_pause),getPendingIntentForKeyCode(app.getApplicationContext(),KeyEvent.KEYCODE_MEDIA_PAUSE)); } else { builder.addAction(R.drawable.ic_media_play,c.getString(R.string.media_play),KeyEvent.KEYCODE_MEDIA_PLAY)); } builder.addAction(R.drawable.ic_media_next,c.getString(R.string.media_next),KeyEvent.KEYCODE_MEDIA_NEXT)); builder.setStyle(new Notification.MediaStyle() .setMediaSession(mediaSession.getSessionToken()) .setShowActionsInCompactVIEw(new int[] {1,2}) ) ); notification = builder.build();解决方法 使用您支持的 *** 作在MediaSession中设置播放状态:
PlaybackState state = new PlaybackState.Builder() .setActions( PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIoUS) .setState(PlaybackState.STATE_PLAYING,position,speed,SystemClock.elapsedRealtime()) .build();mSession.setPlaybackState(state);总结
以上是内存溢出为你收集整理的android – MediaStyle通知没有响应RemoteControl事件.全部内容,希望文章能够帮你解决android – MediaStyle通知没有响应RemoteControl事件.所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)