ffmediaelement
ffmediaelement copied to clipboard
Cannot stop and (re-play) a stream, it gets disposed.
Problems when playing, stopping and playing a stream
I have a problem using stop and play on a rtsp stream.
I am initializing an instance of the MediaElement once by doing m_MediaPlayer = new MediaPlayer();
This instance should live the whole application lifetime.
After this, I open the rtsp stream: await m_MediaPlayer.Open(new Uri(rtspAdress));
The media opens, and when I do m_MediaPlayer.Play();
the stream is displayed in the MediaElement.
Now I want to stop the stream with m_MediaPlayer.Stop();
and play it again. After calling play again, the stream is not diplayed anymore. The log says:
Direct Command 'Close' accepted. Perparing execution. OnStreamReadInterrupt was requested an immediate read exit. EVENT START: BufferingEnded EVENT DONE : BufferingEnded V BLK: 14.388 | CLK: 14.417 | DFT: 29 | IX: 4 | RNG: 48.897% | PQ: 0.0k | TQ: 0.0k Direct Command 'Close' entered MediaState changed: + Close Media closed. OnStreamReadInterrupt was requested an immediate read exit. EVENT START: MediaStateChanged EVENT START: MediaClosed EVENT DONE : MediaStateChanged Direct Command 'Close' completed. Result: True EVENT DONE : MediaClosed Dispose Entered. Waiting for Command Manager processor to stop. Dispose is waiting for pending direct commands. Dispose is closing media. EVENT START: MediaClosed Media closed. EVENT DONE : MediaClosed Dispose completed.
So why is Stop disposing the media? When I create a new player before re-playing and open the stream again, it works. But this takes a moment, so I just wat to stop and start again. Is that possible?
Issue Categories
- [ ] Bug
- [ ] Feature Request
- [X] Question
- [ ] Not sure
Have you tried PauseMedia()?
https://github.com/unosquare/ffmediaelement/blob/ff633961109694455e6f9fc2980b3989380fa7d3/Unosquare.FFME.MediaElement/MediaElement.cs#L52
Have you tried PauseMedia()?
https://github.com/unosquare/ffmediaelement/blob/ff633961109694455e6f9fc2980b3989380fa7d3/Unosquare.FFME.MediaElement/MediaElement.cs#L52
ohha, puase() then play(),it can not work.
So, after none of the solutions, I have tried, worked, I ended up just stopping the media player, when I want to stop the stream. Then, when I want to restart the stream, I just recreate the MediaPlayer member with new(), open the stream and call play. This seems to be the only reliable solution that works for me.
What I wonder is that although I do no call Dispose on the MediaPlayer when I am stopping or recreating the player, (because it takes a few seconds) I do not seem to get any memory leaks caused by non-disposed players. (because I just re-instantiate the MediaPlayer member.