问题
I'm developing a casting application to work in Chrome, using the Queuing feature, and need to know how to obtain any callbacks when the next or previous item in the queue is loaded, because the remote player callbacks don't emit after the second video in the queue loads.
Google's documentation for the Cast framework is terrible, and I've searched throughout the API and haven't found anything.
Here are excerpts from my code (Typescript), specifically, a singleton class:
private _context: cast.framework.CastContext
private _session: cast.framework.CastSession
private _mediaSession: chrome.cast.Session
private _player: cast.framework.RemotePlayer
private _controller: cast.framework.RemotePlayerController
private _mediaQueue: chrome.cast.media.QueueItem[] = []
Queues an item to be added
queueItem(mediaUri: string, mediaType: string, metaData?: AbstractMetaData) {
const mediaInfo = new chrome.cast.media.MediaInfo(mediaUri, mediaType)
if (!!metaData)
mediaInfo.metadata = metaData
const queueItem = new chrome.cast.media.QueueItem(mediaInfo)
this._mediaQueue.push(queueItem)
}
Start the queue
startQueue() {
const request = new chrome.cast.media.QueueLoadRequest(this._mediaQueue)
this._mediaSession.queueLoad(request, this.onMediaLoaded, err => {
console.error(err)
})
}
Callback when the queue is loaded. These properties don't update when the queue moves to the next video, so I'm unable to play/pause and otherwise control the media playback after the first video.
Upon debugging, the _player
object updates isMediaConnected
to false, so it looks like it needs to be updated somehow, but I'm lost.
private onMediaLoaded() {
this._player = new cast.framework.RemotePlayer()
this._controller = new cast.framework.RemotePlayerController(this._player)
this._controller.addEventListener(cast.framework.RemotePlayerEventType.ANY_CHANGE, this.onPlayerEvent)
}
Things are made more difficult by the fact that Google obfuscates their code, so it's near impossible to debug.
Any clues?
来源:https://stackoverflow.com/questions/53902121/google-cast-chrome-sender-callback-on-queue-change