Skip to content

Commit d1d0a89

Browse files
committed
add media retain
1 parent c3bab01 commit d1d0a89

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/LibVLCSharp/Shared/MediaPlayer.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,20 +631,23 @@ public MediaPlayer(Media media)
631631
/// </summary>
632632
public Media? Media
633633
{
634-
get
635-
{
636-
return _media;
637-
}
634+
get => _media;
638635
set
639636
{
640-
if(_media?.NativeReference != IntPtr.Zero)
637+
if(_media != null)
641638
{
642-
_media?.Dispose();
639+
_media.Dispose();
643640
_media = null;
644641
}
645642

646643
_media = value;
647-
Native.LibVLCMediaPlayerSetMedia(NativeReference, value?.NativeReference ?? IntPtr.Zero);
644+
645+
if(_media != null)
646+
{
647+
_media.Retain();
648+
}
649+
650+
Native.LibVLCMediaPlayerSetMedia(NativeReference, _media?.NativeReference ?? IntPtr.Zero);
648651
}
649652
}
650653

0 commit comments

Comments
 (0)