gpt4 book ai didi

android - 尽管将位图放在元数据中,但无法在锁定屏幕上获取专辑封面

转载 作者:行者123 更新时间:2023-11-29 02:41:22 25 4
gpt4 key购买 nike

我无法在锁屏上获取专辑封面,我尝试同时使用 METADATA_KEY_ALBUM_ART 和 METADATA_KEY_ART 但没有任何效果。这是我的代码

    byte[] data = null;
try {
mmr.setDataSource(music.getNowPlayingList().get(currentIndex).getPath());
data = mmr.getEmbeddedPicture();
} catch (Exception e) {
e.printStackTrace();
}
if (music.getNowPlayingList()!=null && music.getNowPlayingList().size()>music.getIndexOfCurrentSong()) {

GildeUtils.getBitmapFromGlide(this,data , new GlideInterface() {
@Override
public void getBitmap(Bitmap bitmap) {
//Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.nowplaying);
mediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART,bitmap)
.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON,bitmap)
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, music.getNowPlayingList().get(currentIndex).getArtist())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, music.getNowPlayingList().get(currentIndex).getAlbum())
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, music.getNowPlayingList().get(currentIndex).getTitle())
.build());
}
});
}

我还制作了 mediastyle 通知,并将专辑封面设置为其他问题中提到的大图标,还添加了 mediasession.setActive(true) 和音频焦点,但似乎没有任何效果。

最佳答案

所以最后它对我有用:) 添加了 Playbackstate 代码,现在一切似乎都工作正常。

GildeUtils.getBitmapFromGlide(this,data , new GlideInterface() {
@Override
public void getBitmap(Bitmap bitmap) {
if(bitmap==null) {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.nowplaying);
}
mediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART,bitmap)
.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON,bitmap)
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, music.getNowPlayingList().get(currentIndex).getArtist())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, music.getNowPlayingList().get(currentIndex).getAlbum())
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, music.getNowPlayingList().get(currentIndex).getTitle())
.build());
PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder();
isLockscreenUpdated = true;
stateBuilder.setActiveQueueItemId(music.getNowPlayingList().get(music.getIndexOfCurrentSong()).getId());

long actions = PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_STOP | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;

stateBuilder.setActions(actions);
stateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, 0, 1.0f);
mediaSession.setPlaybackState(stateBuilder.build());
}


});

关于android - 尽管将位图放在元数据中,但无法在锁定屏幕上获取专辑封面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43828266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com