public MetadataHandler(SystemMediaTransportControls systemMediaTransportControls, ForegroundNotifier notifier, Func <TimeSpan> getPosition, Action <TimeSpan> reportNextEvent, CancellationToken cancellationToken) { if (null == systemMediaTransportControls) { throw new ArgumentNullException("systemMediaTransportControls"); } if (null == notifier) { throw new ArgumentNullException("notifier"); } if (null == getPosition) { throw new ArgumentNullException("getPosition"); } if (null == reportNextEvent) { throw new ArgumentNullException("reportNextEvent"); } _systemMediaTransportControls = systemMediaTransportControls; _notifier = notifier; _getPosition = getPosition; _reportNextEvent = reportNextEvent; _updateTask = new SignalTask(Update, cancellationToken); _metadataSink = new ActionMetadataSink(_updateTask.Fire); }
public MetadataHandler(SystemMediaTransportControls systemMediaTransportControls, ForegroundNotifier notifier, Func<TimeSpan> getPosition, Action<TimeSpan> reportNextEvent, CancellationToken cancellationToken) { if (null == systemMediaTransportControls) throw new ArgumentNullException(nameof(systemMediaTransportControls)); if (null == notifier) throw new ArgumentNullException(nameof(notifier)); if (null == getPosition) throw new ArgumentNullException(nameof(getPosition)); if (null == reportNextEvent) throw new ArgumentNullException(nameof(reportNextEvent)); _systemMediaTransportControls = systemMediaTransportControls; _notifier = notifier; _getPosition = getPosition; _reportNextEvent = reportNextEvent; _updateTask = new SignalTask(Update, cancellationToken); _metadataSink = new ActionMetadataSink(_updateTask.Fire); }
public BackgroundAudioRun(Guid id) { _id = id; _foregroundNotifier = new ForegroundNotifier(id); _timer = new Timer(_ => { var metadataHandler = _metadataHandler; if (null == metadataHandler) { return; } metadataHandler.Refresh(); }, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); _notificationQueue = new ValueSetWorkerQueue(vs => { HandleNotification(vs); return(TplTaskExtensions.CompletedTask); }); _watchdogTimer = new Timer( _ => { Debug.WriteLine("BackgroundAudioRun watchdog"); var barks = 1; try { var foregroundId = BackgroundSettings.ForegroundId; if (!foregroundId.HasValue || _completionSource.Task.IsCompleted) { Interlocked.Exchange(ref _watchdogBarks, 0); StopWatchdog(); return; } barks = Interlocked.Increment(ref _watchdogBarks); if (barks > 3) { Debug.WriteLine("BackgroundAudioRun watchdog exiting"); _completionSource.TrySetCanceled(); Cancel(); return; } _foregroundNotifier.Notify(BackgroundNotificationType.Ping); } catch (Exception ex) { Debug.WriteLine("BackgroundAudioRun watchdog failed: " + ex.ExtendedMessage()); } RequestWatchdog(TimeSpan.FromTicks(WatchdogTimeout.Ticks >> barks)); }, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); }
public BackgroundAudioRun(Guid id) { _id = id; _foregroundNotifier = new ForegroundNotifier(id); _timer = new Timer(_ => { var metadataHandler = _metadataHandler; if (null == metadataHandler) return; metadataHandler.Refresh(); }, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); _notificationQueue = new ValueSetWorkerQueue(vs => { HandleNotification(vs); return TplTaskExtensions.CompletedTask; }); _watchdogTimer = new Timer( _ => { Debug.WriteLine("BackgroundAudioRun watchdog"); var barks = 1; try { var foregroundId = BackgroundSettings.ForegroundId; if (!foregroundId.HasValue || _completionSource.Task.IsCompleted) { Interlocked.Exchange(ref _watchdogBarks, 0); StopWatchdog(); return; } barks = Interlocked.Increment(ref _watchdogBarks); if (barks > 3) { Debug.WriteLine("BackgroundAudioRun watchdog exiting"); _completionSource.TrySetCanceled(); Cancel(); return; } _foregroundNotifier.Notify(BackgroundNotificationType.Ping); } catch (Exception ex) { Debug.WriteLine("BackgroundAudioRun watchdog failed: " + ex.ExtendedMessage()); } RequestWatchdog(TimeSpan.FromTicks(WatchdogTimeout.Ticks >> barks)); }, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); }