Ejemplo n.º 1
0
        /// <summary>
        /// Handler for if playback of a file stopped.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">StoppedEventArgs.</param>
        /// <returns>Task instance.</returns>
        private async void OnPlaybackStoppedAsync(object sender, StoppedEventArgs e)
        {
            await Task.Run(() =>
            {
                bool stoppedExplicitly;

                lock (this)
                {
                    // Dispose timer so we stop reporting the position
                    if (_positionReportTimer != null)
                    {
                        _positionReportTimer.Dispose();
                        _positionReportTimer = null;
                        // Also indicate we don't want to report because the event may have already been fired
                        _doNotReportPosition = true;
                    }

                    // Dispose the wavestream
                    _waveStream.Dispose();

                    // Set resuming to false so we know we're not resuming the next time we start
                    _paused = false;

                    stoppedExplicitly = _stoppedExplicitly;

                    // Signal reset event
                    _resetEvent.Set();
                }

                // If playback wasn't stopped explicitly that meanse the track finished on it's own
                if (stoppedExplicitly)
                {
                    StoppedPlaying?.Invoke(this, new FinishedStoppedPlayingEventArgs(_trackId));
                }
                else
                {
                    FinishedPlaying?.Invoke(this, new FinishedStoppedPlayingEventArgs(_trackId));
                }
            });
        }
Ejemplo n.º 2
0
 protected void ForceStop()
 {
     IsPlaying = false;
     StopAllCoroutines();
     StoppedPlaying?.Invoke();
 }