How to switch sources when casting
Overview
A common use case is to leverage our Player iOS SDK in order to play HLS streams with Fairplay DRM protection on iOS devices. This solution works very well for protecting the content whilst ensuring compatibility with iOS native system.
However, this presents some issues if you'd like to enable casting from your iOS app to devices such as ChromeCast, which doesn't support Fairplay. In scenarios like this, it's possible to instruct your app to switch to a different streaming and DRM format that is ChromeCast compatible, such as DASH + Widevine DRM.
Switch from HLS Fairplay to DASH Widevine
As shown in this github example, it's quite easy to switch to a different streaming and DRM format when casting to a 3rd party device. Here is the relevant piece of code that handles this:
// Provide a different SourceConfig for casting. For local playback we use a HLS stream and for casting a
// Widevine protected DASH stream with the same content.
config.remoteControlConfig.prepareSource = { type, sourceConfig in
switch type {
case .cast:
// Create a different source for casting
guard let streamUrl = URL(string: "https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd"),
let licenseUrl = URL(string: "https://widevine-proxy.appspot.com/proxy") else {
return nil
}
// Create DASHSource as a DASH stream is used for casting
let castSourceConfig = SourceConfig(url: streamUrl, type: .dash)
castSourceConfig.title = sourceConfig.title
castSourceConfig.sourceDescription = sourceConfig.sourceDescription
let widevineConfig = WidevineConfig(license: licenseUrl)
castSourceConfig.drmConfig = widevineConfig
return castSourceConfig
}
}
Updated 3 months ago