Пример #1
0
 public void StopPlaying()
 {
     // Kill the bowls if they are sounding.
     if (PlayThread != null && PlayThread.IsAlive)
     {
         PlayThread.Abort();
         StoppedPlaying.Raise(this, new BowlPlayerEventArgs(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));
                }
            });
        }
Пример #3
0
        void ThreadPlay(int times = 1)
        {
            var args  = new BowlPlayerEventArgs(times);
            var bowls = times.Times().Select(i => Platform.CreateBowlSound(BowlSoundPath)).ToArray();

            Platform.RunOnMainThread(() => StartedPlaying.Raise(this, args));

            foreach (var bowl in bowls)
            {
                bowl.Play(Platform.Preferences.BowlVolumePercentage);
                Platform.ThreadSleep(TimeBetweenBowls);
            }

            Platform.ThreadSleep(AbstractBowlSound.SoundDuration);

            foreach (var bowl in bowls)
            {
                bowl.Dispose();
            }

            Platform.RunOnMainThread(() => StoppedPlaying.Raise(this, args));
        }
Пример #4
0
 protected void ForceStop()
 {
     IsPlaying = false;
     StopAllCoroutines();
     StoppedPlaying?.Invoke();
 }