Android Q Beta 2为音乐通知添加了一个可搜索的进度条,那么如何在Spotify和soundcloud的android Q OS中使用编程来实现?
答案 0 :(得分:2)
您需要向媒体会话添加元数据,例如持续时间和播放状态:
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);
builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, player.getDuration());
mediaSessionCompat.setMetadata(builder.build());
PlaybackStateCompat playbackStateCompat = new PlaybackStateCompat.Builder()
.setActions(
PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE |
PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_REWIND |
PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PAUSE |
PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_SEEK_TO)
.setState(state, position, speedRate)
.build();
mediaSessionCompat.setPlaybackState(playbackStateCompat);
PlaybackStateCompat.ACTION_SEEK_TO还为您提供了寻求能力。