phoboslab / jsmpeg

MPEG1 Video Decoder in JavaScript
MIT License
6.38k stars 1.43k forks source link

jsmpeg.player.pause() not working properly #398

Open YeonwooSung opened 2 years ago

YeonwooSung commented 2 years ago

Hi, I am currently using this library for displaying the rtsp stream that is sent by node.js server with node-rtsp-stream. What I want to do is keep displaying the video stream on the canvas by using jsmpeg player, and pause/restart when the user press the button. Since this library contains the pause(), stop(), and start() methods, I was trying to use those methods for implementing the functionalities. However, for some reason pause() and stop() method never works on my code..

`var client; var canvas; var rtsp_player;

function init_rtsp_video_canvas() { client = new WebSocket('ws://localhost:9999'); canvas = document.querySelector('canvas'); rtsp_player = new jsmpeg(client, {canvas: canvas, loop: true, autoplay: true}); }

function pause_rtsp_client() { rtsp_player.pause(); }

function play_rtsp_client() { rtsp_player.play(); } `

Am I missing something or doing some stupid mistake?

phoboslab commented 2 years ago

.pause(), .stop() and .play() only work for static video files, not for streaming. I should probably mention this in the readme.

It's also debatable how theses should work. Sure .stop() should disconnect the WebSocket and when .play() is called reconnect again.

But what does .pause() do? Does it keep the WebSocket connection open and accumulate all incoming video data in a big buffer? How big is this buffer allowed to get? What happens when I call .play() again? Should it automatically "catch up" to realtime again? If not, we would probably need to have a function that does allow this - i.e. allow seeking in streaming video. This is big can of worms...

So, if you just want to en-/deable the video stream, the best solution right now would be to .destroy() the player when you want to stop it and create a new one, when you want to start again.

I'll look into supporting .stop() and .play() for WebSockets when I can find some more time!

YeonwooSung commented 2 years ago

Ah, nice. Thanks for the reply! Yeh, I thought maybe the play() and stop() method would not work for streaming. And please let me know if you actually make play() and stop() working for the video stream!

russellevans commented 2 years ago

Thanks for this...it has been driving me nuts for days but makes real sense.

I do not know if it is an issue on my implementation but when I .destroy() the player I get this console error.

image