From time to time I'm getting "System.NullReferenceException: Object reference not set to an instance of an object." error while trying to Stop MediaPlayer.
The error appears for about 30-40% of time on Stop action process.
Trace:
System.NullReferenceException: Object reference not set to an instance of an object.
at LibVLCSharp.Shared.MediaEventManager.OnMediaStateChanged (System.IntPtr ptr) [0x00000] in :0
at (wrapper managed-to-native) LibVLCSharp.Shared.MediaPlayer+Native.LibVLCMediaPlayerStop(intptr)
at LibVLCSharp.Shared.MediaPlayer.Stop () [0x00006] in :0
Any thoughts concerning this issue?
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
...
Linked items
0
Link issues together to show that they're related.
Learn more.
But for now, I was not able to reproduce this issue in this test project
In my main project, I was even able to get the Null exception on MediaPlayer.Play() method
System.NullReferenceException: Object reference not set to an instance of an object.
at LibVLCSharp.Shared.MediaEventManager.OnMediaStateChanged (System.IntPtr ptr) [0x00000] in :0
at (wrapper managed-to-native) LibVLCSharp.Shared.MediaPlayer+Native.LibVLCMediaPlayerSetMedia(intptr,intptr)
at LibVLCSharp.Shared.MediaPlayer.set_Media (LibVLCSharp.Shared.Media value) [0x0000c] in :0
at LibVLCSharp.Shared.MediaPlayer.Play (LibVLCSharp.Shared.Media media) [0x00000] in :100
Give me a couple more days to play around with this issue and I let you know if I can reproduce it or not in this test project
Finally figured it out in what conditions this issue is happening.
If we subscribe to Media events directly, like Media.StateChanged or Media.DurationChanged
these events somehow sometimes are fired too late, already after Media was nulled after MediaPlayer.Stopped event. For now, I'm not really sure how this is possible.
Most time this happening on playing live streams (like IPTV) or heavy media >= 1080p files etc.
To escape this issue we need to unsubscribe from all Media events before MediaPlayer stops this Media or even do not subscribe to Media events directly at all, using MediaPlayer events only.
I cannot reproduce, so it's hard to fix. I'd venture that the native side or managed side of libvlc gets released for some reason and the other part is not in sync.
Maybe a libvlc_media_player_retain and/or libvlc_media_retain that would be needed somewhere? Just a guess.
Tested it on Windows, seems the problem is also presented here.
iOS project also added but not able to run it because of local problems with MacOS and Xcode updates
To reproduce the problem wait until video ends and the next video will start play automatically (on Windows 100% of time error appears, on Android from time to time)
The better way to reproduce the problem is through another found issue #73 (closed)
Press "Play and Download" button
Wait a couple of seconds for App to crash
The app will crash because of NullReferenceException for MediaFreed event
Can you try deleting your packages folder and uninstalling reinstalling the package. I don't see any downloads on nuget so you might be on the older version.
Can you try deleting your packages folder and uninstalling reinstalling the package. I don't see any downloads on nuget so you might be on the older version.
I'm sure that the latest version of libvlcsharp is installed. Maybe nuget caches download statistics for a too long time.
Can't repro. Please share steps and stacktrace
In LibVlcSharpTest I also can't reproduce this issue.
But I constantly have it in my main project. And it doesn't depend from where subscriptions were made. I tried a lot of possible situations.
For this reason I'm not using Media events at all, only MediaPlayer events.
But for reproduce purpose I made one Media event subscription for StateChanged and after MediaPlayer.Stop() got this System.NullReferenceException:
[0:] System.NullReferenceException: Object reference not set to an instance of an object
at (wrapper dynamic-method) System.Object.99(intptr,intptr,int,int,int,int)
at (wrapper managed-to-native) LibVLCSharp.Shared.MediaPlayer+Native.LibVLCMediaPlayerStop(intptr)
at LibVLCSharp.Shared.MediaPlayer.Stop () [0x00006] in <b5e9d8ae0ce046aab89b195ca7db7572>:0
at MediaPlayer.Shared.Components.Player+<Stop>d__125.MoveNext () [0x00042]