我相信你需要修改模型/ RemoteJSONSource.java,使其增加了MediaMetadataCompat物品進入軌道ArrayList的。
你需要創建,創建一個MediaMetadataCompat對象「buildFromJSON」的方法。請務必設置儘可能多的媒體屬性。
Google示例顯示了從遠程JSON源添加的媒體。 在我的情況下,我已經將遠程Firebase JSON加載到本地SQLite 數據庫中。所以我從SQLite加載我的媒體。爲此,我修改了 buildFromJson爲buildFromEpisodesCursor,並適當地更改了內容。 (火力地堡可以發送JSON更新如果媒體更改SQLite的。)下面是關鍵代碼塊的一個片段:
public class RemoteJSONSource implements MusicProviderSource {
@Override
public Iterator<MediaMetadataCompat> iterator() {
ArrayList<MediaMetadataCompat> tracks = new ArrayList<>();
EpisodesCursor episodesCursor = getEpisodes();
if (episodesCursor != null) {
while (episodesCursor.moveToNext()) {
tracks.add(buildFromEpisodesCursor(episodesCursor));
}
episodesCursor.close();
}
return tracks.iterator();
}
private MediaMetadataCompat buildFromEpisodesCursor(EpisodesCursor episodesCursor) {
// INITIALIZE THE VARIOUS MEDIA DATA ITEMS YOU NEED HERE (ommitted)
MediaMetadataCompat theMetadata = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id)
.putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, episodeDownloadUrl)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, episodeTitle)
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
.putString(MediaMetadataCompat.METADATA_KEY_WRITER, episodeWriter)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration)
.putString(MediaMetadataCompat.METADATA_KEY_DATE, airdate)
.putLong(MediaMetadataCompat.METADATA_KEY_YEAR, airdate_year)
.putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre)
.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, iconBitmap)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl)
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, episodeTitle)
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, episodeTitle)
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, episodeDescription)
.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, episodeNumber)
.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount)
.putRating(MediaMetadataCompat.METADATA_KEY_RATING, ratingCompat)
.build();
return theMetadata;
}
...
}
UTUBE視頻與鍵模式:
https://www.youtube.com/watch?v=iIKxyDRjecU
https://www.youtube.com/watch?v=XQwe30cZffg
https://www.youtube.com/watch?v=FBC1FgWe5X4&utm_campaign=adp_series_mediabrowserservicecompat_030116&utm_source=medium&utm_medium=blog