2

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 MediaInfos 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)

Knossos
  • 15,802
  • 10
  • 54
  • 91
  • Currently, the idea is that you add items to the queue to play but you don't send the user to the VideoCastControllerActivity and instead, you keep them on the browsing pages so they can add more items to the queue or manage the queue. When the queue loads on the receiver, the mini-controller shows up and if user wants to go to the VideoCastControllerActivity, she can press on mini-controller (which, internally, calls startVideoCastcontrollerActivity). In other words, you can call startVideoCastControllerActivity after you wait for the queue to load. – Ali Naddaf Nov 12 '15 at 15:41
  • If you want a new variation of startVideoCastControllerActivity that takes an array of queue items, feel free to open a feature request. – Ali Naddaf Nov 12 '15 at 15:42
  • Perhaps the reason that it crashes, is that I currently do not use the MiniController at all. Is that conceivable? – Knossos Nov 13 '15 at 05:34
  • You need to provide a way for users to control the playback of the cast content from wherever in your app they are, and mini-controller is the recommended approach based on the UX Checklist, so it is a good idea to add that, regardless of this issue. In your current app, how can a user go back to the VideoCastControllerActivity after they leave that page? – Ali Naddaf Nov 13 '15 at 06:27
  • There is the notification or the Chromecast router button at the moment that lead there. – Knossos Nov 13 '15 at 09:50

2 Answers2

4

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.

Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
  • I attempted to use `queueLoad`, does that work in conjunction with `startVideoCastControllerActivity`? See update #1 in question. – Knossos Nov 12 '15 at 09:09
  • This looks to be the best answer. With sending a Queue directly to the Activity not being possible. – Knossos Nov 13 '15 at 10:41
  • Is it possible to detect that an episode has ended and make a network call to fetch the next episode? I would have to make 20 network calls to get all of the episodes I want to have in the queue when the user starts casting. – Marty Miller Aug 17 '16 at 17:55
0

You will have to create a custom receiver to implement playlist feature. How you implement the playlist structure on receiver using javascript is up to you. See this answer from Ali Nadaf, on why playlist needs to maintained on receiver and not sender.

As far as loading multiple MediaInfo items you will have to look in queueLoad method of castManager and MediaQueueItem class.

Community
  • 1
  • 1
prashant
  • 3,570
  • 7
  • 40
  • 50
  • 2
    Cast SDK now has apis related to queue so it is recommended to use them and in addition, the styled receiver or default receiver can handle queue now so you do not have to write your own receiver for simple cases; since the receiver SDK now understands what a queue is, it informs all the connected devices when a change in the queue happens so most of my comments from that earlier post are now handled by receiver. There is no persistence of playlists and that is something that either a sender can do or a receiver and that needs to use cloud in a complete implementation. – Ali Naddaf Nov 11 '15 at 16:39