Using the CastCompanionLibrary, it is simple to send a MediaInfo
to the Chromecast API to play it.
MediaInfo.Builder media = new MediaInfo.Builder("http://url.to/video.mp4");
VideoCastManager cast = ...
cast.startVideoCastControllerActivity(context, media.build(), 0, true);
What is the recommended way to send multiple MediaInfo
s in order to create a Queue (playlist)?
Update #1:
I attempted to add queueLoad into the code. Making it run after 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);
It crashes the App with this log:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.android.gms.cast.MediaMetadata.getString(java.lang.String)' on a null object reference at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.updateMiniController(SourceFile:309) at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.updateMiniControllers(SourceFile:321) at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.onRemoteMediaPlayerStatusUpdated(SourceFile:2126) at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.access$200(SourceFile:136) at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager$22.onStatusUpdated(SourceFile:1804) at com.google.android.gms.cast.RemoteMediaPlayer.onStatusUpdated(Unknown Source) at com.google.android.gms.cast.RemoteMediaPlayer.zza(Unknown Source) at com.google.android.gms.cast.RemoteMediaPlayer$1.onStatusUpdated(Unknown Source) at com.google.android.gms.cast.internal.zzm.zza(Unknown Source) at com.google.android.gms.cast.internal.zzm.zzbZ(Unknown Source) at com.google.android.gms.cast.RemoteMediaPlayer.onMessageReceived(Unknown Source) at com.google.android.gms.cast.internal.zze$zzb$4.run(Unknown Source)
The recommended approach is to create a MediaQueueItem for each MediaInfo and then use VideoCastManager#queueLoad() and pass an array of MediaQueueItem. It is also possible to start with a single queue item and append to that, or insert somewhere in the queue, etc; there are a number of methods to edit and manage the queue as well.
There are some callbacks from SDK (and CCL) that let you know when a queue is updated, etc so you can use those to update your sender side (e.g. if sender A updates the queue, sender B can use those callbacks to stay in sync). The CastVideos-android app uses that and provides a simple UI to swipe queue items away or reorder them etc.