Chromecast MetaData

牧云@^-^@ 提交于 2019-12-12 05:51:52

问题


Having all sorts of fun trying to get the desired metadata, lockscreen and cast popup behaviour working in a music app that utilizes a custom receiver on Chromecast. Here's where I've got to..

private void _dummyRemotePlay(long id,String mUrl,String artist,String title,String iUrl) {

    // CODE THAT CHANGES BEHAVIOUR
    MediaTrack.Builder b = new MediaTrack.Builder(id,MediaTrack.TYPE_AUDIO);
    b.setSubtype(MediaTrack.SUBTYPE_METADATA);
    // END CODE THAT CHANGES BEHAVIOUR

    MediaMetadata mdata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);  
    mdata.putString(MediaMetadata.KEY_ARTIST, artist);
    mdata.putString(MediaMetadata.KEY_TITLE, title);
    mdata.addImage(new WebImage(Uri.parse(iUrl)));

    MediaInfo mi =  new MediaInfo.Builder(mUrl)
                .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                .setContentType("audio/mpeg")
                .setMetadata(mdata)
                .build();

    MediaQueueItem qi = new 
    MediaQueueItem.Builder(mi).setAutoplay(true).setPreloadTime(20).build();
    MediaQueueItem[] qa = new MediaQueueItem[]{qi,qi}; // Two so SKIP_NEXT works...

    _remoteMediaClient.queueLoad(qa,0,MediaStatus.REPEAT_MODE_REPEAT_OFF, null);}

Without the call to b.setSubType(MediaTrack.SUBTYPE_METADATA) the cast popup works (image, controls etc), a cast notification appears and the cast volume is adjusted by the volume keys. What doesn't work is the lockscreen metadata and controls. The artist is unknown and the controls do nothing.

With the b.setSubType call the lockscreen works fine (artist correctly displayed, controls work). However, there's no cast notification and the cast popup has no media selected (no image, no controls, just volume slider and end cast). Also the volume keys are not bound to cast volume.

Arrived at this point just playing around. Originally called b.build() to create a MediaTrack, added it to a list and called .setMediaTracks(list) on the MediaInfo.builder. Distilled it down to just the above though. The b.setSubType call on just a builder without a MediaTrack being built is enough to switch behaviour.

What I'm looking for is correct lockscreen behaviour, correct cast dialog image and control, volume keys working. I'm indifferent to a cast notification as the app has one anyway. It seems I can't achieve all of this.

来源:https://stackoverflow.com/questions/45135819/chromecast-metadata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!