/// <summary> /// Toggle the playback state of the media source /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void TogglePlaybackState(bool?overridenState = null) { if (Dispatcher.HasThreadAccess) { await m_lock.WaitAsync(); { m_frameSourceIsStreaming = overridenState ?? !m_frameSourceIsStreaming; if (m_frameSourceIsStreaming) { // Start frame source, update button to pause button await m_frameSource?.StartAsync(); UIPlayButton.Icon = new SymbolIcon(Symbol.Pause); UIPlayButton.Label = "Pause"; } else { // Stop frame source, update button to play button await m_frameSource?.StopAsync(); UIPlayButton.Icon = new SymbolIcon(Symbol.Play); UIPlayButton.Label = "Play"; } } m_lock.Release(); } else { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => TogglePlaybackState(overridenState)); } }