Search code examples
javascriptgoogle-chromechromecastgoogle-cast

Google Cast: Detect QueueItems that fail to load


I have a Chrome sender application which uses a Styled Media Receiver to play a queued list of audio tracks.

To queue / autoplay items, I am creating a QueueLoadRequest up-front which contains a URL for each item in the list. At some point during playback (eg, a URL has expired), a track might fail to load.

I want to be able to detect this situation - where an item in a queue has failed to load, but I cannot find anything that does this succinctly.

For example, in the case where you are currently playing an audio track (track 1), and will soon automatically progress to track 2, which has a URL which will fail to load:

A listener registered with Media.addUpdateListener() will get called when track 2 fails to load, but will simply report a playerState of 'Idle'. The idleReason is perpetually given as 'Interrupted'.

In order to determine there has been any kind of error at all, when an 'Idle' state is found, you must make a call to Media.getStatus(). Within the success callback of this call, if you again check the playerState, it is still reported as 'Idle', but the reason is now given as 'Error'. At this point we have to make a fairly large assumption that this has been caused by a media URL failing to load.

There must be a better way?

Remote Debugger Logs

When skipping to the failing track, the remote debugger logs show that the 401 occured and suggests that a LOAD_FAILED message was sent, but it never seems to materialise in the sender.

GET http://<REDACTED_URL_THAT_THROWS_A_401> 401 (Unauthorized)g.load @ cast_receiver.js:64X.tc @ cast_receiver.js:119Wc @ player.js:50Nc @ player.js:46Y.O @ player.js:40h.ta @ player.js:58id @ cast_receiver.js:118qd @ cast_receiver.js:126g.Cc @ cast_receiver.js:135X.sb @ cast_receiver.js:106R.tb @ cast_receiver.js:35Db @ cast_receiver.js:24g.dispatchEvent @ cast_receiver.js:23g.ub @ cast_receiver.js:33Db @ cast_receiver.js:24g.dispatchEvent @ cast_receiver.js:23g.ub @ cast_receiver.js:30
cast_receiver.js:40  [ 50.331s] [cast.receiver.MediaManager] Load metadata error: [object Object]$b @ cast_receiver.js:40Yb.hc @ cast_receiver.js:40B.log @ cast_receiver.js:13J @ cast_receiver.js:14X.qb @ cast_receiver.js:123g.qb @ cast_receiver.js:61zb @ cast_receiver.js:20wb @ cast_receiver.js:21(anonymous function) @ cast_receiver.js:19
cast_receiver.js:40  [ 50.890s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender","data":"{\"type\":\"setappstate\",\"statusText\":\"Now Casting: <REDACTED_AUDIO_TITLE>\"}"}
cast_receiver.js:40  [ 50.918s] [cast.receiver.MediaManager] Sending error message to 
cast_receiver.js:40  [ 50.924s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.media","senderId":"","data":"{\"requestId\":0,\"type\":\"LOAD_FAILED\"}"}
cast_receiver.js:40  [ 50.934s] [cast.receiver.MediaManager] MediaManager message received
cast_receiver.js:40  [ 50.940s] [cast.receiver.MediaManager] Dispatching MediaManager getStatus event
cast_receiver.js:40  [ 50.945s] [cast.receiver.MediaManager] onGetStatus
cast_receiver.js:40  [ 50.950s] [cast.receiver.MediaManager] onGetStatus: {"mediaSessionId":1,"sessionId":"5D841D2B-AB1E-4CD3-ACC9-B308A164E77C","requestId":70783069}
cast_receiver.js:40  [ 50.957s] [cast.receiver.MediaManager] Sending status message to 11:client-99231
cast_receiver.js:40  [ 50.964s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.media","senderId":"11:client-99231","data":"{\"type\":\"MEDIA_STATUS\",\"status\":[{\"mediaSessionId\":1,\"playbackRate\":1,\"playerState\":\"IDLE\",\"currentTime\":0,\"supportedMediaCommands\":15,\"volume\":{\"level\":1,\"muted\":false},\"media\":{\"contentId\":\"https://<REDACTED_URL_THAT_THROWS_A_401>\",\"streamType\":\"BUFFERED\",\"contentType\":\"audio/mp3\",\"metadata\":{\"type\":3,\"metadataType\":3,\"title\":\"<REDACTED_AUDIO_TITLE>\",\"artist\":\"<REDACTED_ARTIST>\",\"trackNumber\":2,\"images\":[{\"url\":\"//<REDACTED_IMAGE_URL>\"}]}},\"currentItemId\":2,\"idleReason\":\"ERROR\"}],\"requestId\":70783069}"}

Solution

  • As per the comments above, this has been raised as an issue against the Cast SDK.