silvermine / videojs-chromecast

MIT License
148 stars 75 forks source link

Error when resetting player before playback begins #85

Open Ddog800 opened 3 years ago

Ddog800 commented 3 years ago

If the player is loaded and then player.reset() is called before the playback ever begins, this plugin throws the following error:

Uncaught TypeError: Cannot read property 'src' of null
    at constructor._playSource (silvermine-videojs-chromecast.min.js:4005)
    at new constructor (silvermine-videojs-chromecast.min.js:3968)
    at Player.loadTech_ (video.js:24403)
    at Player.doReset_ (video.js:26795)
    at Player.reset (video.js:26779)
    at <anonymous>:1:8

This is causing a problem in my case due to how we're handling the player lifetime. We create the player on page load, in a hidden Bootstrap modal. When the user clicks on a video, it opens the modal and sets the player source. When the modal is closed, we have an event listener fire on the modal close event that will grab the player instance and then call player.reset() to clear the source and other things. The error thrown by this plugin then causes the the event listener to prematurely end, and the modal never closes.

In testing, I've determined that this error will always appear any time the player is reset before playback begins. It won't always be a breaking error depending on what's going on, but it does throw an error where it should not.

I've tested with Video.js 7.8.2 and 7.10.2 and the Chromecast plugin 1.2.2.

fvilpoix commented 3 years ago

Hi,

I have the same problem: I'm manually handling a playlist. if I'm casting a video, then trigger the next video via videojs.loadMedia(), then this error is thrown.

After checking, the loadMedia calls reset, so it's exactly the same issue.