Queue mutiliples image on Chromecast with GCKMediaQueueItem

1.2k views Asked by At

I would like to send multiples images to the Chromecast and use them as a screensaver.
I am able to send them one by one with [self.mediaControlChannel loadMedia:mediaInformation]; but when I wanted to use the queueing capabilities, I started to got some problems.

First I tried to use queueLoadItems: to load multiples GCKMediaQueueItem:

GCKMediaInformation *mediaInformation = [[GCKMediaInformation alloc] initWithContentID:[url absoluteString]
                                                                            streamType:GCKMediaStreamTypeNone
                                                                           contentType:@"image/jpeg"
                                                                              metadata:nil
                                                                        streamDuration:5
                                                                            customData:nil];

GCKMediaQueueItem *mediaQueue =  [[GCKMediaQueueItem alloc] initWithMediaInformation:mediaInformation
                                                                            autoplay:true
                                                                           startTime:startTime
                                                                         preloadTime:3.0f
                                                                      activeTrackIDs:nil
                                                                          customData:nil];


[mediaArray addObject:mediaQueue];



NSInteger requestId = [self.mediaControlChannel queueLoadItems:mediaArray startIndex:0 repeatMode:GCKMediaRepeatModeAllAndShuffle ];
if (requestId == kGCKInvalidRequestID) {
    NSLog(@"WARN queueLoadItems: the message could not be sent");
} else {
    NSLog(@"queueLoadItems: OK");  
}

But no success, even if - (void)mediaControlChannel:(GCKMediaControlChannel *)mediaControlChannel didCompleteLoadWithSessionID:(NSInteger)sessionIDis called, and the image of the first GCKMediaQueueItem is visible on the TV. The second GCKMediaQueueItem never appears.

I tried to force to move to the next item with [self.mediaControlChannel queueNextItem];, but no luck either. If I check how many items are in the queue with [[self.mediaControlChannel mediaStatus] queueItemCount], I got "0", meaning that the queue is empty.

And if I set the startIndex:1, for example, the second item is displayed on the TV. So it looks like that all the items are loaded.

Then I tried to used [self.mediaControlChannel queueInsertItem:mediaQueue beforeItemWithID:kGCKMediaQueueInvalidItemID];and again I have the same issue: Only the first image of the queue is visible and I have 0 items in my queueItemCount:.

If I enable the logger I got this message:

-[GCKMediaControlChannel mediaSessionID]  Calling a method that requires a media status with no media status, ignoring; 
make sure that media is loaded, the media channel has received a status, and that this method is not being called while the device manager is attempting to reconnect

So I tried to insert the items after didCompleteLoadWithSessionIDis called. The message got away, but I still have no items in my queueItemCount:

If I keep looking inside the logs I found those lines:

-[GCKMediaControlChannel didReceiveTextMessage:]  message received: {"requestId":7,"type":"INVALID_REQUEST","reason":"INVALID_MEDIA_SESSION_ID"}
-[GCKMediaControlChannel didReceiveTextMessage:]  Received unexpected error: Invalid Request.

Thanks to this question I know that I can use a custom receiver to enqueue multiples items using loadMedia:and a custom receiver, but it looks like what I am trying to do can be possible with the default receiver and the last SDK update (2.7).

Any help will be greatly appreciated.

2

There are 2 answers

1
Ali Naddaf On BEST ANSWER

The default/styled receivers handle queues of audio or video items but not images; that is due to the fact that the queueing capabilities of the receiver SDK is built around those two media types and not images. With an audio/video item, there is a "duration" and they start playing and they reach their end and at that time, SDK moves to the next item (it basically learns about the end of an item by listening to the MediaElement events). With images and an image tag, you do not have such things, hence SDK doesn't attempt to do anything. So, in short, you'd need to write your own custom receiver and when doing that, you may not benefit much from the queueing APIs even on the sender side; you need to send "messages" (on your own custom namespace) with the urls of the images (and other info you need) to your receiver and then, in your custom receiver, get the array of images and push them to an image tag one by one, or something like that.

0
Carlos Alan On

Idk if you are still looking for a solution but for me this worked

NSMutableArray *mediaArray = [NSMutableArray array];
[mediaArray addObject:mediaQueue];

Since NSArray is not a "mutable" class, meaning it's not designed to be modified after it's created.