I'm trying to create a custom CAF receiver with my own HTML5 video element and supporting library. Since I'm using my own <video>
element, I'm setting up the PlayerManager
instance as follows:
// My custom HTML5 video player
const player = new Player(document.querySelector('#my-video'))
const context = cast.framework.CastReceiverContext.getInstance()
const playerManager = context.getPlayerManager()
playerManager.setMediaElement(document.querySelector('#my-video'))
// Now, I need to override some of the playerManager methods such as play/pause, etc
const overrides = {
getCurrentTimeSec () {
return player.currentTime
},
getPlayerState () {
const PlayerState = cast.framework.messages.PlayerState
if (!player.ready || !player.source) {
return PlayerState.IDLE
}
return player.paused ? PlayerState.PAUSED : PlayerState.PLAYING
},
getDurationSec () {
return player.duration
},
pause: player.pause,
play: player.play,
seek: player.seek,
load: (loadRequestData) => {
return new Promise((resolve, reject) => {
// Parse loadRequestData and load the media accordingly
...
})
}
Object.assign(playerManager, overrides)
context.start();
Since I need custom handling of the incoming 'load' request in cases where the incoming video is protected, I need to set up a custom load
handler. My problem seems to be that playerManager.load
is never called.
Note that all of this works great for normal unprotected HTML5 videos since the incoming loadRequestData
can be directly understood and used by PlayerManager
. It is in cases where I need to do some extra processing that things begin to fail.
I have already tried running my business logic as described by Google:
playerManager.setMessageInterceptor(
cast.framework.messages.MessageType.LOAD,
request => {
...
})
The problem in this approach is that even though I'm able to ask my Player
library to load the video successfully, the intercept needs to either return null or the modified request
.
When I don't return anything, the playerManager
thinks that there is no request to load media.
If I do return a 'modified request', then the default media loading logic kicks in which inevitably fails due to the URL being 'malformed'.
In either case, the playerManager
instance reports not being ready for receiving playback commands.
What is the right approach for setting up a CAF receiver with a custom <video>
element?
cast.receiver.media.Player
seems to have a lot of the same functionality. Any idea if I will be able to use a custom<video>
element with this class?