From 613545845d92e90b08a5473edd0a1ad0e14a2811 Mon Sep 17 00:00:00 2001 From: Athul Raj Date: Tue, 4 Apr 2023 22:46:44 +0530 Subject: [PATCH] some exception handling --- Totoro.Core/ViewModels/WatchViewModel.cs | 35 +++++++++++------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Totoro.Core/ViewModels/WatchViewModel.cs b/Totoro.Core/ViewModels/WatchViewModel.cs index a59b7b03..9f368d28 100644 --- a/Totoro.Core/ViewModels/WatchViewModel.cs +++ b/Totoro.Core/ViewModels/WatchViewModel.cs @@ -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()