public async Task Seek(TimeSpan time) { logger.Info(time.ToString()); var token = activeTaskCts.Token; try { var resumeNeeded = player.GetState() == ESPlayer.ESPlayerState.Paused; if (resumeNeeded) { await stateChangedSubject .AsObservable() .FirstAsync(state => state == PlayerState.Playing) .ToTask(token); token.ThrowIfCancellationRequested(); } using (await asyncOpSerializer.LockAsync(token)) { // Set suspend clock. Clock is not available during seek, but required during Suspend/Resume _suspendClock = time; token.ThrowIfCancellationRequested(); await SeekStreamInitialize(token); var seekToTime = await Client.Seek(time, token); _dataClock.SetClock(time, token); EnableInput(); _dataClock.Start(); await StreamSeek(seekToTime, resumeNeeded, token); // Invalidate _suspendClock _suspendClock = PlayerClockProviderConfig.InvalidClock; } } catch (SeekException e) { logger.Error(e); playbackErrorSubject.OnNext($"Seek Failed, reason \"{e.Message}\""); throw; } catch (OperationCanceledException) { logger.Info("Operation Cancelled"); } catch (Exception e) { logger.Error(e); playbackErrorSubject.OnNext("Seek Failed"); } }
public async Task Seek(TimeSpan time) { logger.Info(time.ToString()); var token = activeTaskCts.Token; try { var resumeNeeded = player.GetState() == ESPlayer.ESPlayerState.Paused; if (resumeNeeded) { _suspendResumeLogic.SetAsyncOpRunningState(true); await stateChangedSubject .AsObservable() .FirstAsync(state => state == PlayerState.Playing) .ToTask(token); token.ThrowIfCancellationRequested(); _suspendResumeLogic.SetAsyncOpRunningState(false); } await SeekStreamInitialize(token); var seekTotime = await Client.Seek(time, token); EnableInput(); await _dataClock.SetClock(time, token); await StreamSeek(seekTotime, resumeNeeded, token); } catch (SeekException e) { logger.Error(e); playbackErrorSubject.OnNext($"Seek Failed, reason \"{e.Message}\""); throw; } catch (OperationCanceledException) { logger.Info("Operation Cancelled"); } catch (Exception e) { logger.Error(e); playbackErrorSubject.OnNext("Seek Failed"); } }