-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the ability to select a subtitle track on the video player page. Added a SubtitleAudioTrackSelector UserControl. This UserControl hosts the subtitle tracks and will also host the audio tracks from which a user can select a track. Introduced a MediaTrackService which can be injected to provider some methods. Methods it provide are at this moment the retrieval of subtitle tracks and the preferred subtitle track. Due to LibVLC not being able to be injected by a dependency injector due to several reasons, this service needs to be initialized by calling the initialize method and providing it with a reference to a (initialized!) MediaPlayer instance. This service can be expanded to perform more general MediaPlayer tasks as well in the future if need be. Added a ValueConverterGroup enabling the chaining of value converters. Added a custom exception which gets thrown when one of the the MediaTrackService methods get called without the service being initialized. Added MediaTrackService to the dependency Injector container in App.xaml.cs.
- Loading branch information
Showing
14 changed files
with
431 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
OneDrive-Cloud-Player/Exceptions/ServiceNotInitializedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace OneDrive_Cloud_Player.Exceptions | ||
{ | ||
internal class ServiceNotInitializedException : Exception | ||
{ | ||
public ServiceNotInitializedException() { } | ||
|
||
public ServiceNotInitializedException(string message) : base(message) { } | ||
|
||
public ServiceNotInitializedException(string message, Exception inner) : base(message, inner) { } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
OneDrive-Cloud-Player/Models/Interfaces/IMediaTrackService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using LibVLCSharp.Shared; | ||
using LibVLCSharp.Shared.Structures; | ||
|
||
namespace OneDrive_Cloud_Player.Models.Interfaces | ||
{ | ||
public interface IMediaTrackService | ||
{ | ||
/// <summary> | ||
/// Needs to be called before using the service. | ||
/// </summary> | ||
/// <param name="mediaPlayer"></param> | ||
/// <returns></returns> | ||
IMediaTrackService Initialize(ref MediaPlayer mediaPlayer); | ||
TrackDescription GetPreferredSubtitleTrack(); | ||
TrackDescription[] GetSubtitleTracks(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
OneDrive-Cloud-Player/Services/Converters/ValueConverterGroup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Windows.UI.Xaml.Data; | ||
|
||
namespace OneDrive_Cloud_Player.Services.Converters | ||
{ | ||
public class ValueConverterGroup : List<IValueConverter>, IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, string language) | ||
{ | ||
return this.Aggregate(value, (current, converter) => converter.Convert(current, targetType, parameter, language)); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, string language) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using LibVLCSharp.Shared; | ||
using LibVLCSharp.Shared.Structures; | ||
using OneDrive_Cloud_Player.Exceptions; | ||
using OneDrive_Cloud_Player.Models.Interfaces; | ||
using Windows.Storage; | ||
|
||
namespace OneDrive_Cloud_Player.Services | ||
{ | ||
public class MediaTrackService :IMediaTrackService | ||
{ | ||
private MediaPlayer _mediaPlayer; | ||
private bool _isInitialized = false; | ||
private readonly ApplicationDataContainer _UserSettings; | ||
|
||
/// <summary> | ||
/// It is important to always initialize this service again after the mediaplayer changes (i.e. after a reload); | ||
/// </summary> | ||
public MediaTrackService() | ||
{ | ||
this._UserSettings = ApplicationData.Current.LocalSettings; | ||
} | ||
|
||
/// <summary> | ||
/// Due to LibVLCSharp's inability for the MediaPlayer to be put into a service, we need to get a reference to the MediaPlayer ourselves instead. | ||
/// Initialize this service by parsing the MediaPlayer object reference for its media tracks. | ||
/// </summary> | ||
public IMediaTrackService Initialize(ref MediaPlayer mediaPlayer) | ||
{ | ||
Debug.WriteLine("initializing service"); | ||
_mediaPlayer = mediaPlayer; | ||
_isInitialized = true; | ||
return this; | ||
} | ||
|
||
private void CheckInitializationState() | ||
{ | ||
if (!_isInitialized) | ||
{ | ||
throw new ServiceNotInitializedException(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get the preferred subtitle track. When no preferred subtitle track is found, a default will be returned. | ||
/// </summary> | ||
/// <returns><see cref="TrackDescription"/> Preferred subtitle track or default</returns> | ||
public TrackDescription GetPreferredSubtitleTrack() | ||
{ | ||
CheckInitializationState(); | ||
|
||
//Enable or disable default subtitle based on user setting. | ||
if (!(bool)_UserSettings.Values["ShowDefaultSubtitles"]) | ||
{ | ||
return _mediaPlayer.SpuDescription.ElementAtOrDefault(0); | ||
} | ||
|
||
return _mediaPlayer.SpuDescription.ElementAtOrDefault(1); | ||
} | ||
|
||
public TrackDescription[] GetSubtitleTracks() | ||
{ | ||
CheckInitializationState(); | ||
return _mediaPlayer.SpuDescription; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.