ffmpeginteropx / FFmpegInteropX

FFmpeg decoding library for Windows 10 UWP and WinUI 3 Apps
Apache License 2.0
210 stars 53 forks source link

Unexpected Live Stream Interruption and OnMediaEnded Trigger with FFmpegInteropX During Navigation #357

Closed hondek closed 1 year ago

hondek commented 1 year ago

I'm encountering an issue while streaming live MP3 from a URL using the FFmpegInteropX library. When I start the live stream and interact with the application, for instance, navigating through several pages repeatedly, the live stream unexpectedly stops, triggering the OnMediaEnded event. However, if I do nothing within the application, everything works fine and the stream continues uninterrupted.

I've set up a repository where you can check this issue: https://github.com/hondek/RadioFFmpegTest

This is a simple C# UWP project; all you need to do is run it and navigate to different pages a few times to reproduce the error.

All the code that initiates the live stream is located in the ViewModel/ShellViewModel.cs file, specifically within the Initialize method.

I'd appreciate any help you could provide. Thank you.

lukasf commented 1 year ago

Hi @hondek, the reason is that you do not keep a reference to the FFmpegMediaSource you create. It is garbage collected during playback, when the GC detects increased memory usage (during navigation). If you add a FFmpegMediaSource field in your ShellViewModel and store the instance there, playback should be fine.

We have a PR open to remove this requirement (#320). But until that is merged, you need to manually keep reference of the current FFmpegMediaSource.

hondek commented 1 year ago

Thank you!