Skip to content

Commit

Permalink
add some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Apr 3, 2023
1 parent 93c3cfc commit ecb6c62
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 51 deletions.
8 changes: 6 additions & 2 deletions Totoro.Core/Services/PlaybackStateStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions Totoro.Core/ViewModels/WatchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public WatchViewModel(IProviderFactory providerFactory,
SetVideoStreamModel(stream);
await MediaPlayer.SetMedia(stream);
MediaPlayer.Play(GetPlayerTime());
});

}, RxApp.DefaultExceptionHandler.OnError);

MediaPlayer
.DurationChanged
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 4 additions & 9 deletions Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ internal class LibVLCMediaPlayerWrapper : IMediaPlayer
private readonly Subject<TimeSpan> _positionChanged = new();

public IObservable<Unit> Paused => _paused;

public IObservable<Unit> Playing => _playing;

public IObservable<Unit> PlaybackEnded => _ended;

public IObservable<TimeSpan> PositionChanged => _positionChanged;

public IObservable<TimeSpan> DurationChanged => _durationChanged;

public IMediaTransportControls TransportControls { get; private set; }

public bool IsInitialized { get; private set; }
Expand All @@ -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)
Expand Down
46 changes: 9 additions & 37 deletions Totoro.WinUI/Media/Wmp/WinUIMediaPlayerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TimedTextSource, string> _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)
Expand Down Expand Up @@ -197,43 +185,27 @@ private async Task<MediaSource> GetMediaSource(string url, Dictionary<string, st
{
_httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
}

var result = await AdaptiveMediaSource.CreateFromUriAsync(uri, _httpClient);
if (result.Status == AdaptiveMediaSourceCreationStatus.Success)
{
this.Log().Info("Creating adaptive media from {0}", uri);
this.Log().Info("With headers {0}", string.Join(";", headers.Select(x => $"{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<Unit> 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);
}
}
}
2 changes: 1 addition & 1 deletion Totoro.WinUI/Views/WatchPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</Grid.RowDefinitions>

<ctk:SwitchPresenter Value="{x:Bind ViewModel.MediaPlayerType}">
<ctk:Case Value="{x:Bind m:MediaPlayerType.WindowsMediaPlayer}">
<ctk:Case IsDefault="True" Value="{x:Bind m:MediaPlayerType.WindowsMediaPlayer}">
<MediaPlayerElement
x:Name="MediaPlayerElement"
AreTransportControlsEnabled="True"
Expand Down

0 comments on commit ecb6c62

Please sign in to comment.