【问题标题】:ExoPlayer Notification Manager, hide seekbar from notificationExoPlayer 通知管理器,从通知中隐藏搜索栏
【发布时间】:2020-09-07 11:22:54
【问题描述】:
我想从通知中隐藏搜索栏视图。我尝试了不同的解决方案(禁用计时器),但没有奏效。
我使用此代码块来禁用搜索操作:
mediaSessionConnector.setEnabledPlaybackActions(PlaybackStateCompat.ACTION_PLAY or
PlaybackStateCompat.ACTION_PAUSE or
PlaybackStateCompat.ACTION_STOP or
PlaybackStateCompat.ACTION_PLAY_PAUSE)
有人知道这个案子吗?
谢谢,
【问题讨论】:
标签:
android
android-notifications
exoplayer2.x
【解决方案1】:
只是不要在 MediaMetadataProvider 中设置持续时间。我的例子:
mediaSessionConnector.setMediaMetadataProvider(player -> {
if (currentEpisode == null || !currentEpisode.isValid() || realm.isClosed()) {
return null;
}
long duration;
if (player.getDuration() < 0)
duration = currentEpisode.getDurationTime();
else
duration = player.getDuration();
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST,
currentEpisode.getPodcast().getArtistName());
builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM,
currentEpisode.getPodcast().getCollectionName());
builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, currentEpisode.getTitle());
builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, currentEpisode.getImageUrl());
builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, currentEpisode.id);
// if (duration > 0) {
// builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration);
// }
try {
Bitmap icon;
if (notificationCover != null) {
icon = notificationCover;
} else {
icon = BitmapFactory.decodeResource(getResources(),
R.drawable.placeholder);
}
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, icon);
} catch (OutOfMemoryError e) {
KLog.e("oom");
}
return builder.build();
});