Reputation: 545
What is the best way to stop a video using VideoJS? I have been using the pause() method to stop a video and then hiding the video tag but I came across a use case where I would attempt to stop the video while it is still loading/buffering. The problem with calling the pause() method while the video is still buffering is that the video isn't yet playing, so the pause() method does nothing.
So what happens is that the video continues to buffer and after the video buffers, the video begins playing. (Because I hide the video when stopping the video, I can't see the video playing, but I can hear it still playing.)
To solve this issue, I could listen for when the player dispatches the "timeupdate" event and then pause the video immediately if the video is supposed to be paused. However, that seems like a hack and is bound for errors for other use cases.
I really wish VideoJS had a dedicated stop() function. Maybe in the next version. @see https://github.com/zencoder/video-js/issues/296
Can anyone tell me how to stop a video if it is still buffering?
UPDATE: So I tried to implement the solution that I had originally thought of: call the "stop" function when the "timeupdate" event is dispatched and the player is supposed to be stopped. However, I found something strange. The player was not dispatching any events while it was in the stop state.
I then created a timeOut function to call every second. Within the timeOut function, I checked the current time of the videoJS player (i.e. _myPlayer.currentTime()) and wrote it to the console. The current Time always stayed the same: 0 seconds. However, I could hear the video advancing/playing. It seemed like the video player was disembodied to what I was hearing.
UPDATE2: Just in case the info is valuable, I updated the original post to include the fact that I hide the video tag when I stop the video: i.e. $("#playerID").hide()
Upvotes: 3
Views: 5332
Reputation: 1295
It looks like there is no solution for this problem in this VideoJS version, maybe in a future release.
For now you could try to load a single frame 'empty' video in place of the currently buffering video. And set the preload to "off".
Or use the "timeupdate" to call the pause() as you already suggested.
Hope it helps..
Upvotes: 1