Monday 16 November 2020

Handling Chromecast load errors in web-based sender

The documentation for a web-based Chromecast sender says that castSession.loadMedia() returns a promise. Therefore, I should be able to catch errors in an async function like so:

const castSession = cast.framework.CastContext.getInstance().getCurrentSession();

const mediaInfo = new chrome.cast.media.MediaInfo(
  'https://example.com/stream.m3u8',
  'application/vnd.apple.mpegurl'
);

const loadRequest = new chrome.cast.media.LoadRequest(mediaInfo);

try {
  await castSession.getSessionObj().loadMedia(loadRequest);
} catch(e) {
  console.error(e);
}

Unfortunately, this doesn't work. Whatever load error I'm getting seems to occur sometime between the downloading of the HLS manifest and before playback. The loadMedia() promise resolves successfully, so there's no error to catch. The sender's developer console has an error:

cast_sender.js:85 Uncaught TypeError: d is not a function
    at cast_sender.js:85
    at V.onMessage (cast_sender.js:91)
    at S.h (cast_sender.js:71)
(anonymous) @ cast_sender.js:85
V.onMessage @ cast_sender.js:91
S.h @ cast_sender.js:71

Clearly, some sort of error is making it back to the client, and it seems that there should be some event handler that isn't set, but I don't see any documentation for how to catch the error.

How can I catch media load errors, general media errors, and any other errors on the Chromecast sender?



from Handling Chromecast load errors in web-based sender

No comments:

Post a Comment