Skip to content

Commit

Permalink
SQUASH
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKauffmann committed Mar 13, 2023
1 parent e9fd737 commit bf6eed0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
13 changes: 0 additions & 13 deletions OneDrive-Cloud-Player/Exceptions/ServiceNotInitializedException.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using LibVLCSharp.Shared;
using LibVLCSharp.Shared.Structures;
using OneDrive_Cloud_Player.Exceptions;

namespace OneDrive_Cloud_Player.Models.Interfaces
{
Expand Down
1 change: 0 additions & 1 deletion OneDrive-Cloud-Player/OneDrive-Cloud-Player.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Exceptions\ServiceNotInitializedException.cs" />
<Compile Include="Models\GraphData\CachedDrive.cs" />
<Compile Include="Models\GraphData\CachedDriveItem.cs" />
<Compile Include="Models\GraphData\OneDriveCache.cs" />
Expand Down
15 changes: 10 additions & 5 deletions OneDrive-Cloud-Player/Services/MediaTrackService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibVLCSharp.Shared;
using LibVLCSharp.Shared.Structures;
using OneDrive_Cloud_Player.Exceptions;
using OneDrive_Cloud_Player.Models.Interfaces;
using System;
using System.Diagnostics;
using System.Linq;
using Windows.Storage;
Expand All @@ -28,7 +28,12 @@ public MediaTrackService()
/// </summary>
public IMediaTrackService Initialize(ref MediaPlayer mediaPlayer)
{
Debug.WriteLine("initializing MediaTrackService");
if (_isInitialized)
{
throw new InvalidOperationException("Service already initialized!");
}

Debug.WriteLine("initializing {0}", this.GetType().Name);
_mediaPlayer = mediaPlayer;
_isInitialized = true;
return this;
Expand All @@ -37,12 +42,12 @@ public IMediaTrackService Initialize(ref MediaPlayer mediaPlayer)
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <exception cref="ServiceNotInitializedException"></exception>
/// <exception cref="InvalidOperationException"></exception>
private void CheckInitializationState()
{
if (!_isInitialized)
{
throw new ServiceNotInitializedException();
throw new InvalidOperationException("Service not initialized!");
}
}

Expand All @@ -57,7 +62,7 @@ public TrackDescription GetPreferredSubtitleTrack()
//Enable or disable default subtitle based on user setting.
if (!(bool)_userSettings.Values["ShowDefaultSubtitles"])
{
return _mediaPlayer.SpuDescription.ElementAtOrDefault(0);
return default;
}

return _mediaPlayer.SpuDescription.ElementAtOrDefault(1);
Expand Down
22 changes: 10 additions & 12 deletions OneDrive-Cloud-Player/ViewModels/VideoPlayerPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private async void InitializeLibVLC(InitializedEventArgs eventArgs)

// Create LibVLC instance.
LibVLC = new LibVLC(eventArgs.SwapChainOptions);
MediaPlayer = new MediaPlayer(LibVLC);
_mediaPlayer = new MediaPlayer(LibVLC);
_mediaTrackService.Initialize(ref _mediaPlayer);
// Subscribe to events only once.
_mediaPlayer.Playing += MediaPlayer_Playing;
Expand Down Expand Up @@ -344,19 +344,16 @@ await App.Current.UIDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
private async void MediaPlayer_Playing(object sender, EventArgs e)
{
Debug.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff") + ": Media is playing");

if (_isFirstPlaying || _isReloading)
{
TrackDescription[] subtitleTracks;
TrackDescription selectedSubtitleTrack;
TrackDescription[] subtitleTracks = null;
TrackDescription selectedSubtitleTrack = default;

subtitleTracks = await Task.Run(() =>
await Task.Run(() =>
{
return _mediaTrackService.GetEmbeddedSubtitleTracks();
});

selectedSubtitleTrack = await Task.Run(() =>
{
return _mediaTrackService.GetPreferredSubtitleTrack();
subtitleTracks = _mediaTrackService.GetEmbeddedSubtitleTracks();
selectedSubtitleTrack = _mediaTrackService.GetPreferredSubtitleTrack();
});

if (_isFirstPlaying)
Expand All @@ -367,6 +364,7 @@ private async void MediaPlayer_Playing(object sender, EventArgs e)
if (_isReloading)
{
_isReloading = false;
// Retrieve the previously selected subtitle track.
selectedSubtitleTrack = subtitleTracks.FirstOrDefault(subtitleTrack => subtitleTrack.Id == _selectedSubtitleTrack.Id);
}

Expand Down Expand Up @@ -500,10 +498,10 @@ private void SetSubtitleTrackById(int subtitleTrackId)

private void SetMediaVolume(int volumeLevel)
{
if (MediaPlayer is null)
if (_mediaPlayer is null)
{
Debug.WriteLine("Error: SetMediaVolumeLevel: Could not set the volume.");
return; // Return when the MediaPlayer is null so it does not cause exception.
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;
Expand Down

0 comments on commit bf6eed0

Please sign in to comment.