-
Notifications
You must be signed in to change notification settings - Fork 7
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
Implemented audio selector #92
Open
TimGels
wants to merge
2
commits into
master
Choose a base branch
from
audio-selector
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
57 changes: 57 additions & 0 deletions
57
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,57 @@ | ||
using LibVLCSharp.Shared; | ||
using LibVLCSharp.Shared.Structures; | ||
using System.Threading.Tasks; | ||
|
||
namespace OneDrive_Cloud_Player.Models.Interfaces | ||
{ | ||
public interface IMediaTrackService | ||
{ | ||
/// <summary> | ||
/// Needs to be called before using the service and before subscribing to other libvlcsharp events.<br /> | ||
/// 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.<br /> | ||
/// Initialize this service by parsing the MediaPlayer object reference for its media tracks. | ||
/// </summary> | ||
/// <param name="mediaPlayer"></param> | ||
/// <returns></returns> | ||
IMediaTrackService Initialize(ref MediaPlayer mediaPlayer); | ||
|
||
/// <summary> | ||
/// Get the preferred subtitle track. When no preferred subtitle track is found, a default will be returned. | ||
/// <br /> | ||
/// <i>Note: This method should not be called on a LibVLC thread. | ||
/// <see href="https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/docs/best_practices.md#do-not-call-libvlc-from-a-libvlc-event-without-switching-thread-first">Here</see> is more info on why.</i> | ||
/// </summary> | ||
/// <returns><see cref="TrackDescription"/> Preferred subtitle track or default</returns> | ||
/// <exception cref="ServiceNotInitializedException"></exception> | ||
TrackDescription GetPreferredSubtitleTrack(); | ||
|
||
/// <summary> | ||
/// Get the embedded subtitle tracks in the media file. | ||
/// <br /> | ||
/// <i>Note: This method should not be called on a LibVLC thread. | ||
/// <see href="https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/docs/best_practices.md#do-not-call-libvlc-from-a-libvlc-event-without-switching-thread-first">Here</see> is more info on why.</i> | ||
/// </summary> | ||
/// <returns>Array containing <see cref="TrackDescription"/>'s or empty when no tracks are available</returns> | ||
TrackDescription[] GetEmbeddedSubtitleTracks(); | ||
|
||
|
||
/// <summary> | ||
/// Get the preferred audio track. When no preferred audio track is found, a default will be returned. | ||
/// <br /> | ||
/// <i>Note: This method should not be called on a LibVLC thread. | ||
/// <see href="https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/docs/best_practices.md#do-not-call-libvlc-from-a-libvlc-event-without-switching-thread-first">Here</see> is more info on why.</i> | ||
/// </summary> | ||
/// <returns><see cref="TrackDescription"/> Preferred audio track or default</returns> | ||
/// <exception cref="ServiceNotInitializedException"></exception> | ||
TrackDescription GetPreferredAudioTrack(); | ||
|
||
/// <summary> | ||
/// Get the embedded audio tracks in the media file. | ||
/// <br /> | ||
/// <i>Note: This method should not be called on a LibVLC thread. | ||
/// <see href="https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/docs/best_practices.md#do-not-call-libvlc-from-a-libvlc-event-without-switching-thread-first">Here</see> is more info on why.</i> | ||
/// </summary> | ||
/// <returns>Array containing <see cref="TrackDescription"/>'s or empty when no tracks are available</returns> | ||
TrackDescription[] GetEmbeddedAudioTracks(); | ||
} | ||
} |
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,110 @@ | ||
using LibVLCSharp.Shared; | ||
using LibVLCSharp.Shared.Structures; | ||
using OneDrive_Cloud_Player.Models.Interfaces; | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Windows.Storage; | ||
|
||
namespace OneDrive_Cloud_Player.Services | ||
{ | ||
/// <summary> | ||
/// Manage the media tracks of the libvlcsharp media player instance. | ||
/// </summary> | ||
public class MediaTrackService : IMediaTrackService | ||
{ | ||
private MediaPlayer _mediaPlayer; | ||
private bool _isInitialized = false; | ||
private readonly ApplicationDataContainer _userSettings; | ||
|
||
public MediaTrackService() | ||
{ | ||
_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) | ||
{ | ||
if (_isInitialized) | ||
{ | ||
throw new InvalidOperationException("Service already initialized!"); | ||
} | ||
|
||
Debug.WriteLine(String.Format("initializing {0}", GetType().Name)); | ||
_mediaPlayer = mediaPlayer; | ||
_isInitialized = true; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
/// <exception cref="InvalidOperationException"></exception> | ||
private void CheckInitializationState() | ||
{ | ||
if (!_isInitialized) | ||
{ | ||
throw new InvalidOperationException("Service not initialized!"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
/// <returns> <inheritdoc/></returns> | ||
public TrackDescription GetPreferredSubtitleTrack() | ||
{ | ||
CheckInitializationState(); | ||
TrackDescription[] subtitleTracks = _mediaPlayer.SpuDescription; | ||
|
||
if (_mediaPlayer.SpuCount <= 1) | ||
{ | ||
return default; | ||
} | ||
|
||
// Return default track subtitle (when possible, like in mkv) depending on the user setting. | ||
if ((bool)_userSettings.Values["ShowDefaultSubtitles"]) | ||
{ | ||
return subtitleTracks.First(subtitleTrack => subtitleTrack.Id == _mediaPlayer.Spu); | ||
} | ||
else | ||
{ | ||
// Return the "disabled" indicator track positioned at index 0. | ||
return _mediaPlayer.SpuDescription.ElementAt(0); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
/// <returns><inheritdoc/></returns> | ||
public TrackDescription[] GetEmbeddedSubtitleTracks() | ||
{ | ||
CheckInitializationState(); | ||
return _mediaPlayer.SpuDescription; | ||
} | ||
|
||
public TrackDescription GetPreferredAudioTrack() | ||
{ | ||
CheckInitializationState(); | ||
TrackDescription[] audioTracks = _mediaPlayer.AudioTrackDescription; | ||
|
||
if (_mediaPlayer.AudioTrackCount <= 1) | ||
{ | ||
return default; | ||
} | ||
|
||
// Return the first actual audio track. | ||
return _mediaPlayer.AudioTrackDescription.ElementAt(1); | ||
} | ||
|
||
public TrackDescription[] GetEmbeddedAudioTracks() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing documentation, other methods do have the inheritdoc directives. |
||
{ | ||
CheckInitializationState(); | ||
return _mediaPlayer.AudioTrackDescription; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing documentation, other methods do have the inheritdoc directives.