使用 CastCompanionLibrary 将"playlist"推送到 Chromecast



使用CastCompanionLibrary,将MediaInfo发送到Chromecast API播放它非常简单。

MediaInfo.Builder media = new MediaInfo.Builder("http://url.to/video.mp4");
VideoCastManager cast = ...
cast.startVideoCastControllerActivity(context, media.build(), 0, true);

建议使用何种方式发送多个MediaInfo以创建队列(播放列表)?

更新#1:

我试图将queueLoad添加到代码中。使其在startVideoCastControllerActivity之后运行。

MediaInfo.Builder info = new MediaInfo.Builder("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
info.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED);
info.setContentType("video/mp4");
MediaQueueItem[] items = new MediaQueueItem[] {
        new MediaQueueItem.Builder(info.build()).build(),
        new MediaQueueItem.Builder(info.build()).build(),
        new MediaQueueItem.Builder(info.build()).build()
};
cast.queueLoad(items, 0, 0, null);

它使用以下日志使应用程序崩溃:

java.lang.NullPointerException:尝试调用虚拟方法'java.lang.Stringcom.google.android.gms.cast.MediaMetadata.getString(java.lang.String)'在的null对象引用上com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.updateMiniController(源文件:309)在com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.updateMiniControllers(源文件:321)在com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.onRemoteMediaPlayerStatusUpdated(源文件:2126)在com.google.android.libraries.cast.companylibrary.cast.VideoCastManager.access 200美元(源文件:136)在com.google.android/library.cast.companylibrary.cast.VideoCastManager$22.onStatusUpdated(源文件:1804)在com.google.android.gms.cast.RemoteMediaPlayer.onStatusUpdated(未知来源),网址为com.google.android.gms.cast.RemoteMediaPlayer.zza(未知来源)com.google.android.gms.cast.RemoteMediaPlayer$1.onStatusUpdated(未知来源),网址:com.google.android.gms.cast.internal.zzm.zza(未知来源),网址为com.google.android.gms.cast.internal.zzm.zzbZ(未知来源)com.google.android.gms.cast.RemoteMediaPlayer.onMessageReceived(未知来源:com.google.android.gms.cast.internal.zze$zzb$4.run(未知来源)

建议的方法是为每个MediaInfo创建一个MediaQueueItem,然后使用VideoCastManager#queueLoad()并传递一个MediaQueueItem数组。也可以从单个队列项目开始并附加到该项目,或者插入队列中的某个位置,等等;还有许多方法可以编辑和管理队列。

SDK(和CCL)中有一些回调可以让您知道队列何时更新等,因此您可以使用这些回调来更新发送方(例如,如果发送方a更新队列,则发送方B可以使用这些回叫来保持同步)。CastVideos安卓应用程序使用它,并提供了一个简单的用户界面,可以将队列项目扫走或重新排序等。

您必须创建一个自定义接收器来实现播放列表功能。如何使用javascript在接收器上实现播放列表结构取决于您自己。看看Ali Nadaf的回答,为什么播放列表需要在接收者而不是发送者上维护。

至于加载多个MediaInfo项,您必须查看castManager和MediaQueueItem类的queueLoad方法。

最新更新