From ecb6c6276bc799219a9e27c804b7db8c0bc17cfe Mon Sep 17 00:00:00 2001 From: Athul Raj Date: Mon, 3 Apr 2023 22:25:48 +0530 Subject: [PATCH] add some logs --- Totoro.Core/Services/PlaybackStateStorage.cs | 8 +++- Totoro.Core/ViewModels/WatchViewModel.cs | 5 +- .../Media/Vlc/LibVLCMediaPlayerWrapper.cs | 13 ++---- .../Media/Wmp/WinUIMediaPlayerWrapper.cs | 46 ++++--------------- Totoro.WinUI/Views/WatchPage.xaml | 2 +- 5 files changed, 23 insertions(+), 51 deletions(-) diff --git a/Totoro.Core/Services/PlaybackStateStorage.cs b/Totoro.Core/Services/PlaybackStateStorage.cs index f5ec2b7c..58959c2c 100644 --- a/Totoro.Core/Services/PlaybackStateStorage.cs +++ b/Totoro.Core/Services/PlaybackStateStorage.cs @@ -15,21 +15,23 @@ public PlaybackStateStorage(ILocalSettingsService localSettingsService) public double GetTime(long id, int episode) { - this.Log().Debug($"Checking saved time for Anime: {id}, Episode: {episode}"); + this.Log().Info($"Checking saved time for Anime: {id}, Episode: {episode}"); if (!_recents.ContainsKey(id)) { + this.Log().Info("Saved time not found"); return 0; } if (!_recents[id].ContainsKey(episode)) { + this.Log().Info("Saved time not found"); return 0; } var time = _recents[id][episode]; - this.Log().Debug($"Saved time found {time}"); + this.Log().Info($"Saved time found {time}"); return time; } @@ -45,6 +47,8 @@ public void Reset(long id, int episode) return; } + this.Log().Info("Reset time for Id:{0} Ep:{1}", id, episode); + _recents[id].Remove(episode); if (_recents[id].Count == 0) diff --git a/Totoro.Core/ViewModels/WatchViewModel.cs b/Totoro.Core/ViewModels/WatchViewModel.cs index 598bb7bc..a59b7b03 100644 --- a/Totoro.Core/ViewModels/WatchViewModel.cs +++ b/Totoro.Core/ViewModels/WatchViewModel.cs @@ -158,7 +158,8 @@ public WatchViewModel(IProviderFactory providerFactory, SetVideoStreamModel(stream); await MediaPlayer.SetMedia(stream); MediaPlayer.Play(GetPlayerTime()); - }); + + }, RxApp.DefaultExceptionHandler.OnError); MediaPlayer .DurationChanged @@ -189,8 +190,8 @@ public WatchViewModel(IProviderFactory providerFactory, this.WhenAnyValue(x => x.SubStreams) .WhereNotNull() - .Select(x => x.Count() > 1) .Log(this, "SubStreams :", x => string.Join(",", x)) + .Select(x => x.Count() > 1) .ToPropertyEx(this, x => x.HasMultipleSubStreams); NativeMethods.PreventSleep(); diff --git a/Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs b/Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs index 0bd01dab..15dd06cd 100644 --- a/Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs +++ b/Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs @@ -17,15 +17,10 @@ internal class LibVLCMediaPlayerWrapper : IMediaPlayer private readonly Subject _positionChanged = new(); public IObservable Paused => _paused; - public IObservable Playing => _playing; - public IObservable PlaybackEnded => _ended; - public IObservable PositionChanged => _positionChanged; - public IObservable DurationChanged => _durationChanged; - public IMediaTransportControls TransportControls { get; private set; } public bool IsInitialized { get; private set; } @@ -37,18 +32,18 @@ public void Dispose() public void Pause() { - _mp.Pause(); + _mp?.Pause(); } public void Play() { - _mp.Play(); + _mp?.Play(); } public void Play(double offsetInSeconds) { - _mp.Play(); - _mp.SeekTo(TimeSpan.FromSeconds(offsetInSeconds)); + _mp?.Play(); + _mp?.SeekTo(TimeSpan.FromSeconds(offsetInSeconds)); } public void SeekTo(TimeSpan ts) diff --git a/Totoro.WinUI/Media/Wmp/WinUIMediaPlayerWrapper.cs b/Totoro.WinUI/Media/Wmp/WinUIMediaPlayerWrapper.cs index 3c594339..f29b3cd8 100644 --- a/Totoro.WinUI/Media/Wmp/WinUIMediaPlayerWrapper.cs +++ b/Totoro.WinUI/Media/Wmp/WinUIMediaPlayerWrapper.cs @@ -2,6 +2,7 @@ using System.IO; using System.Text.Json; using ReactiveMarbles.ObservableEvents; +using Splat; using Totoro.WinUI.Contracts; using Windows.Media.Core; using Windows.Media.Playback; @@ -11,26 +12,13 @@ namespace Totoro.WinUI.Media.Wmp; -public sealed class WinUIMediaPlayerWrapper : IMediaPlayer +public sealed class WinUIMediaPlayerWrapper : IMediaPlayer, IEnableLogger { private readonly CustomMediaTransportControls _transportControls; private readonly MediaPlayer _player = new(); private readonly HttpClient _httpClient = new(); private readonly Dictionary _ttsMap = new(); - //private readonly FFmpegInteropX.MediaSourceConfig _ffmpegOptions = new() - //{ - // ReadAheadBufferEnabled = true, - // ReadAheadBufferDuration = TimeSpan.FromSeconds(30), - // ReadAheadBufferSize = 50 * 1024 * 1024, - // FFmpegOptions = new Windows.Foundation.Collections.PropertySet - // { - // { "reconnect", 1 }, - // { "reconnect_streamed", 1 }, - // { "reconnect_on_network_error", 1 }, - // } - //}; private bool _isHardSub; - //private FFmpegInteropX.FFmpegMediaSource _ffmpegMediaSource; private bool _isDisposed; public WinUIMediaPlayerWrapper(IWindowService windowService) @@ -197,43 +185,27 @@ private async Task GetMediaSource(string url, Dictionary $"{x.Key}={x.Value}"))); + return MediaSource.CreateFromAdaptiveMediaSource(result.MediaSource); } else { + this.Log().Info("Creating media from http stream"); HttpRandomAccessStream httpStream = await HttpRandomAccessStream.CreateAsync(_httpClient, uri); return MediaSource.CreateFromStream(httpStream, httpStream.ContentType); } } else { - return MediaSource.CreateFromUri(uri); - } - } + this.Log().Info("Creating media from : {0}", uri); - public Task SetFFMpegMedia(VideoStreamModel streamModel) - { - try - { - _player.Source = MediaSource.CreateFromStream(streamModel.Stream.AsRandomAccessStream(), "video/x-matroska"); - return Task.FromResult(Unit.Default); - //_videoStreamModel = streamModel; - //_ffmpegMediaSource = streamModel.Stream is null - // ? await FFmpegInteropX.FFmpegMediaSource.CreateFromUriAsync(streamModel.StreamUrl, _ffmpegOptions) - // : await FFmpegInteropX.FFmpegMediaSource.CreateFromStreamAsync(streamModel.Stream.AsRandomAccessStream(), _ffmpegOptions); - - //var mediaSource = _ffmpegMediaSource.CreateMediaPlaybackItem(); - //mediaSource.TimedMetadataTracks.SetPresentationMode(0, TimedMetadataTrackPresentationMode.PlatformPresented); - //_player.Source = mediaSource; - - //return Unit.Default; - } - catch - { - return Task.FromResult(Unit.Default); + return MediaSource.CreateFromUri(uri); } } } diff --git a/Totoro.WinUI/Views/WatchPage.xaml b/Totoro.WinUI/Views/WatchPage.xaml index 85735f5d..db8c0c8d 100644 --- a/Totoro.WinUI/Views/WatchPage.xaml +++ b/Totoro.WinUI/Views/WatchPage.xaml @@ -21,7 +21,7 @@ - +