Skip to content

Commit

Permalink
some exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Apr 4, 2023
1 parent ecb6c62 commit 6135458
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions Totoro.Core/ViewModels/WatchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,31 @@ public WatchViewModel(IProviderFactory providerFactory,
.WhereNotNull()
.Subscribe(async stream =>
{
SetVideoStreamModel(stream);
await MediaPlayer.SetMedia(stream);
MediaPlayer.Play(GetPlayerTime());

}, RxApp.DefaultExceptionHandler.OnError);

MediaPlayer
.DurationChanged
.Throttle(TimeSpan.FromSeconds(1))
.Subscribe(async duration =>
{
if (Anime is null)
try
{
return;
SetVideoStreamModel(stream);
await MediaPlayer.SetMedia(stream);
MediaPlayer.Play(GetPlayerTime());
}

var timeStamps = await timestampsService.GetTimeStamps(Anime.Id, EpisodeModels.Current.EpisodeNumber, duration.TotalSeconds);

if (!timeStamps.Success)
catch (Exception ex)
{
return;
this.Log().Error(ex);
}
});

MediaPlayer
.DurationChanged
.Where(_ => Anime is not null)
.Throttle(TimeSpan.FromSeconds(1))
.SelectMany(duration => timestampsService.GetTimeStamps(Anime.Id, EpisodeModels.Current.EpisodeNumber, duration.TotalSeconds))
.Where(timeStamp => timeStamp.Success)
.Subscribe(timeStamps =>
{
foreach (var item in mediaEventListeners)
{
item.SetTimeStamps(timeStamps);
}
});
}, RxApp.DefaultExceptionHandler.OnError);

this.WhenAnyValue(x => x.Anime)
.WhereNotNull()
Expand Down

0 comments on commit 6135458

Please sign in to comment.