[Android] Random crash when creating and disposing multiple MediaPlayer instances
Summary
The Android App randomly crashes when using multiple MediaPlayer
instances and switching to multiple streams.
The Crash logs are random everytime.
Crash Logs 1:crash_1.txt
Crash Logs 2:crash_2.txt
Minimal project and steps to reproduce
- Create
CollectionView
and add show 4 stream in Grid.
<CollectionView x:Name="MosaicColView">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" VerticalItemSpacing="5" HorizontalItemSpacing="5" Span="2"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<vlc:VideoView MediaPlayer="{Binding MediaPlayer}">
</vlc:VideoView>
<DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
- Add pagination feature to navigate to next/previous streams.
- Create new instances of
MediaPlayer
everytime page is navigated in. (Please do not confuse this with ContentPage)
MediaPlayer = new MediaPlayer(LibVlc)
{
EnableHardwareDecoding = false,
FileCaching = 2000,
AspectRatio = "Original",
Scale = 0
};
var media = new Media(LibVlc, new Uri(StreamUrl)));
MediaPlayer?.Play(media);
- Stop and Dispose
MediaPlayer
instances everytime the page is navigated away. In this scenario, I am creating 4 instances every time.
MediaPlayer?.Stop();
MediaPlayer?.Dispose();
- Quickly navigate to the next or previous pages.
What is the current bug behavior?
The App crashes randomly in Android. The Crash logs are different everytime. The Logs are not telling if the crash is due to LibVLCSharp or due to LibVLC. Please refer attached crash logs.
What is the expected correct behavior?
The App should not crash.
Does it work on other platforms? Does it work with the official VLC apps?
The same implementation works for iOS.
Relevant LibVLC logs and/or screenshots
- None
Environment
- OS: Android
- Version Any
- Device: Any
- LibVLC version and architecture 3.5.0+
- LibVLCSharp version 3.5.0+