Search code examples
htmlhttp-live-streamingchromecastgoogle-cast

Playing Ads on Chromecast With the Media Player Library


Dear Stack Overflow,

I am currently developing a Chromecast app for an existing video streaming service, and would like to play ads on our chromecast port.

Our video content is HLS, so we are using the Media Player Library (0.7.0) for video playback and our ad content is currently MP4 content. On its own, all ad and video content will play fine independently on the device. No encoding or CORS issues ;)

I would like to be able to play midroll ad content without having to unload the current HLS content (especially the master M3U8)

The most obvious solution is to stop the Media Player, play the ad content, and resume the HLS content at the ad break. This causes the buffered content to be cleared, and when the video is resumed, we start again from a low bitrate, reload the buffer, and ramp up quality.

Is there a way to give the Media Player Library a hint at what bitrate to resume, or not completely unload the buffer while playing the ad, so the video resumes faster?

If that is not possible, we have another problem.

Our content is protected, and requires an authentication token in the query string of the request for the master M3U8. (eg. http://example.com/video.m3u8?token=abc) In that response, an authorization cookie is set that must be included in subsequent requests for M3U8s and TS files, and is valid for a very extended period.

The authentication token is only valid for ~5 minutes. In our solution to ad midroll playback, we lose the master m3u8 when we begin ad playback, and have to re-request it. If the video resumes, and it has been longer than 5 minutes, then the auth token has expired, and we need to renew the token.

Is there any way to get the Media Player Library to cache the Master M3U8 between playback? Is there another solution where we do not have to retrieve a new token after every ad break?

Thank you in advance.


Solution

  • The best way to achieve this is by splicing the ads into the HLS playlist and use #EXT-X-DISCONTINUITY to signal when an ad starts and ends.