Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Fix Media leaks #208

Merged
merged 1 commit into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/LibVLCSharp/Shared/MediaPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,12 @@ public Media? Media
/// <returns>true if successful</returns>
public bool Play()
{
Media?.AddOption(Configuration);
var media = Media;
if(media != null)
{
media.AddOption(Configuration);
media.Dispose();
}
return Native.LibVLCMediaPlayerPlay(NativeReference) == 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ private void VideoView_SizeChanged(object sender, EventArgs args)

try
{
var videoTrack = mediaPlayer.Media?.Tracks?.FirstOrDefault(t => t.Id == selectedVideoTrack);
var media = mediaPlayer.Media;
MediaTrack? videoTrack = null;
if (media != null)
{
videoTrack = media.Tracks?.FirstOrDefault(t => t.Id == selectedVideoTrack);
media.Dispose();
}
return videoTrack == null ? (VideoTrack?)null : ((MediaTrack)videoTrack).Data.Video;
}
catch (Exception)
Expand Down
15 changes: 14 additions & 1 deletion src/LibVLCSharp/Shared/MediaPlayerElement/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,20 @@ public StateManager(IDispatcher? dispatcher) : base(dispatcher)
/// <summary>
/// Gets the media resource locator
/// </summary>
public string? MediaResourceLocator => MediaPlayer?.Media?.Mrl;
public string? MediaResourceLocator
{
get
{
var mrl = string.Empty;
var media = MediaPlayer?.Media;
if(media != null)
{
mrl = media.Mrl;
media.Dispose();
}
return mrl;
}
}

/// <summary>
/// Gets a value indicating whether the playback is playing
Expand Down