我已实施媒体恢复以在手机重启后显示最近的曲目。根据开发博客点击播放按钮后,“静态媒体控件将与从您的通知创建的媒体控件交换”但对我来说它没有交换,我有静态媒体控制通知和由此创建的新媒体通知。有什么问题。系统如何知道应该交换什么通知?
我的代码:
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid,
@Nullable Bundle rootHints) {
//ANDROID 11 playback resumption - https://developer.android.com/guide/topics/media/media-controls#java
if (rootHints != null) {
if (rootHints.getBoolean(BrowserRoot.EXTRA_RECENT)) {
// Return a tree with a single playable media item for resumption.
Bundle extras = new Bundle();
extras.putBoolean(BrowserRoot.EXTRA_RECENT, true);
KLog.d(clientPackageName + " -> onGetRoot BrowserRoot.EXTRA_RECENT");
return new BrowserRoot(MEDIA_ID_RECENT, extras);
}
}
return new BrowserRoot(MEDIA_ID_ROOT, null);
}
播放:
@Override
public void onPlay() {
super.onPlay();
CommonOperations.crashLog("mediaSessionCallback onPlay");
KLog.d("mediaSessionCallback onPlay");
fakeStartForeground();
if (realm == null || realm.isClosed()) {
initRealm();
}
if (playlist != null && currentEpisode != null) {
play();
} else {
List<Episode> unfinished = UserDataManager.getInstance(URLPlayerService.this)
.getUnfinishedEpisodesData();
if (unfinished != null && unfinished.size() > 0) {
EpisodePlaylist list = new EpisodePlaylist(unfinished);
URLPlayerService.startActionSetPlaylist(URLPlayerService.this, list, 0, true);
} else {
KLog.w("stopself");
if (!wasForegroudStart) {
fakeStartForeground();
}
CommonOperations
.crashLog("stopself #" + new Exception().getStackTrace()[0].getLineNumber());
stopSelf();
cancelNotification();
}
}
}