Skip to content

Commit

Permalink
Replaced public mediaplayer property calls with private.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGels committed Mar 12, 2023
1 parent d3620bb commit 80dfb78
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions OneDrive-Cloud-Player/ViewModels/VideoPlayerPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ private async void InitializeLibVLC(InitializedEventArgs eventArgs)
MediaPlayer = new MediaPlayer(LibVLC);
MediaTrackService.Initialize(ref _mediaPlayer);
// Subscribe to events only once.
MediaPlayer.Playing += MediaPlayer_Playing;
MediaPlayer.Paused += MediaPlayer_Paused;
MediaPlayer.TimeChanged += MediaPlayer_TimeChanged;
_mediaPlayer.Playing += MediaPlayer_Playing;
_mediaPlayer.Paused += MediaPlayer_Paused;
_mediaPlayer.TimeChanged += MediaPlayer_TimeChanged;
// Listen to the first volumechanged event, after which we can initialise the volume level correctly.
MediaPlayer.VolumeChanged += UpdateInitialVolume;
_mediaPlayer.VolumeChanged += UpdateInitialVolume;
reloadIntervalTimer.Elapsed += ReloadIntervalTimer_Elapsed;
fileNameOverlayTimer.Elapsed += FileNameOverlayTimer_Elapsed;

Expand Down Expand Up @@ -333,7 +333,7 @@ private async void UpdateInitialVolume(object sender, MediaPlayerVolumeChangedEv
// Updating the GUI should happen on the dispatcher.
await App.Current.UIDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
MediaPlayer.VolumeChanged -= UpdateInitialVolume;
_mediaPlayer.VolumeChanged -= UpdateInitialVolume;
MediaVolumeLevel = (int)App.Current.UserSettings.Values["MediaVolume"];
IsBackBtnEnabled = true;
});
Expand Down Expand Up @@ -380,7 +380,7 @@ await App.Current.UIDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
await App.Current.UIDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
//Sets the max value of the seekbar.
VideoLength = MediaPlayer.Length;
VideoLength = _mediaPlayer.Length;
PlayPauseButtonFontIcon = "\xE769";
});
Expand All @@ -402,11 +402,11 @@ await App.Current.UIDispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
// when the user is not seeking.
if (!IsSeeking)
{
// Sometimes the MediaPlayer is already null upon
// Sometimes the _mediaPlayer is already null upon
// navigating away and this still gets called.
if (MediaPlayer != null)
if (_mediaPlayer != null)
{
TimeLineValue = MediaPlayer.Time;
TimeLineValue = _mediaPlayer.Time;
}
}
});
Expand Down Expand Up @@ -470,20 +470,20 @@ private async Task PlayMedia(long startTime = 0)
// Play the OneDrive file.
using (Media media = new Media(LibVLC, new Uri(mediaDownloadURL)))
{
MediaPlayer.Play(media);
_mediaPlayer.Play(media);
}

if (MediaPlayer is null)
if (_mediaPlayer is null)
{
Debug.WriteLine("PlayMedia: Error: Could not set start time.");
return;
}

MediaPlayer.Time = startTime;
_mediaPlayer.Time = startTime;
}

/// <summary>
/// Set the subtitle track used in the <see cref="MediaPlayer"/> by id.
/// Set the subtitle track used in the <see cref="_mediaPlayer"/> by id.
/// </summary>
/// <param name="subtitleTrackId">Subtitle track id</param>
private void SetSubtitleTrackById(int subtitleTrackId)
Expand All @@ -499,7 +499,7 @@ private void SetMediaVolume(int volumeLevel)
return; // Return when the MediaPlayer is null so it does not cause exception.
}
App.Current.UserSettings.Values["MediaVolume"] = volumeLevel; // Set the new volume in the MediaVolume setting.
MediaPlayer.Volume = volumeLevel;
_mediaPlayer.Volume = volumeLevel;
UpdateVolumeButtonFontIcon(volumeLevel);
}

Expand Down Expand Up @@ -557,7 +557,7 @@ private void Seeked()
/// <param name="ms"></param>
public void SeekBackward(double ms)
{
SetVideoTime(MediaPlayer.Time - ms);
SetVideoTime(_mediaPlayer.Time - ms);
}

/// <summary>
Expand All @@ -566,7 +566,7 @@ public void SeekBackward(double ms)
/// <param name="ms"></param>
public void SeekForward(double ms)
{
SetVideoTime(MediaPlayer.Time + ms);
SetVideoTime(_mediaPlayer.Time + ms);
}

/// <summary>
Expand All @@ -581,7 +581,7 @@ private void SetVideoTime(double time)
Debug.WriteLine(" + Reloading media.");
ReloadCurrentMedia();
}
MediaPlayer.Time = Convert.ToInt64(time);
_mediaPlayer.Time = Convert.ToInt64(time);
}

//TODO: Implement a Dialog system that shows a dialog when there is an error.
Expand All @@ -600,21 +600,21 @@ private async void ReloadCurrentMedia()
/// </summary>
private void ChangePlayingState()
{
bool isPlaying = MediaPlayer.IsPlaying;
bool isPlaying = _mediaPlayer.IsPlaying;

if (isPlaying)
{
MediaPlayer.SetPause(true);
_mediaPlayer.SetPause(true);
}
else if (!isPlaying)
{
MediaPlayer.SetPause(false);
_mediaPlayer.SetPause(false);
}
}

public void StopMedia()
{
MediaPlayer.Stop();
_mediaPlayer.Stop();
TimeLineValue = 0;
Dispose();
// Go back to the last page.
Expand Down Expand Up @@ -750,20 +750,20 @@ public void Deactivate(object parameter)
/// </summary>
public void Dispose()
{
// TODO: Reproduce MediaPlayer == null
Debug.Assert(MediaPlayer != null);
// TODO: Reproduce _mediaPlayer == null
Debug.Assert(_mediaPlayer != null);
Debug.Assert(LibVLC != null);

// Unsubscribe from event handlers.
MediaPlayer.Playing -= MediaPlayer_Playing;
MediaPlayer.Paused -= MediaPlayer_Paused;
MediaPlayer.TimeChanged -= MediaPlayer_TimeChanged;
_mediaPlayer.Playing -= MediaPlayer_Playing;
_mediaPlayer.Paused -= MediaPlayer_Paused;
_mediaPlayer.TimeChanged -= MediaPlayer_TimeChanged;
reloadIntervalTimer.Elapsed -= ReloadIntervalTimer_Elapsed;
fileNameOverlayTimer.Elapsed -= FileNameOverlayTimer_Elapsed;

// Dispose of the LibVLC instance and the mediaplayer.
var mediaPlayer = MediaPlayer;
MediaPlayer = null;
var mediaPlayer = _mediaPlayer;
_mediaPlayer = null;
mediaPlayer?.Dispose();
LibVLC?.Dispose();
LibVLC = null;
Expand Down

0 comments on commit 80dfb78

Please sign in to comment.