Exemplo n.º 1
0
 /// <summary>
 /// Stop playback and empty the play queue.
 /// </summary>
 public void ClearQueue()
 {
     ToccataModel.Stop();
     this.PlayQueue.Clear();
 }
Exemplo n.º 2
0
        //private DispatcherTimer _dtimer = null;
        private async void ThrottledPlaybackStateChanged(MediaPlayer player)
        {
            if (_playbackStateChangePending)
            {
                // A change has already been noted, and the 'state changed' handler will get called anyway some time within the next 100ms
                return;
            }
            else
            {
                _playbackStateChangePending = true;

                await Task.Delay(100); // allow 100ms for subsequent state changes to come in

                _playbackStateChangePending = false;

                //
                // Now adjust the appearance of the Pause/Play button as needed, and kick off playback of the next track in the queue, if there is one.
                //
                if (player.PlaybackSession == null) // error - never started
                {
                }
                else if (player.PlaybackSession.PlaybackState == MediaPlaybackState.Paused)
                {
                    bool trackFinished = false; //at the end of a track?
                    if (player.PlaybackSession.Position != TimeSpan.Zero && player.PlaybackSession.Position.Add(TimeSpan.FromSeconds(1)) >= player.PlaybackSession.NaturalDuration)
                    {
                        // Position is not at the start of the media, and is equal/near to the duration of the player's media,
                        // This means we are at the end of a track
                        trackFinished = true;
                    }

                    MainPage.SetPlayButtonAppearance(false);              // Set the Play button to display a "play" label, and do 'play' when tapped.

                    if (trackFinished)                                    // paused, and at the end of a track
                    {
                        MainPage.SetNowPlaying("");                       // "***FINISHED: " + player.PlaybackSession.PlaybackState.ToString() + " " + player.PlaybackSession.Position.TotalSeconds.ToString() + "/" + player.PlaybackSession.NaturalDuration.TotalSeconds.ToString()); // set the text label at the bottom of the slider to blank.

                        if (PlayQueue.Count > 0)                          // (this is just defensive coding, it should always be true)
                        {
                            PlayQueue.RemoveAt(0);                        // We've finished this track, so remove it from the top of the play queue.
                        }
                        if (PlayQueue.Count > 0)                          // if there is now a track at the top of the queue ...
                        {
                            ToccataModel.Play(this.PlayQueue[0].storage); // ... start playing it.
                        }
                        else
                        {
                            ToccataModel.Stop(); // ... otherwise, we should hard-stop the player, leaving it ready to play something, when something is queued up.
                        }
                    }
                    else // paused but not finished the track - e.g. because the user tapped the Pause button.
                    {
                        // MainPage.SetNowPlaying("***PAUSED: " + player.PlaybackSession.PlaybackState.ToString()+" "+ player.PlaybackSession.Position.TotalSeconds.ToString()+"/"+ player.PlaybackSession.NaturalDuration.TotalSeconds.ToString());
                    }
                }
                else // playing, buffering, opening, none, or whatever
                {
                    if (player.PlaybackSession.PlaybackState == MediaPlaybackState.Playing)
                    {
                        MainPage.SetPlayButtonAppearance(true); // Set the Play button to display a "pause" label, and do 'pause' when tapped.
                    }
                    else // could be 'buffering', 'opening' or 'none' - anyhow, it's a state in which the media is not (yet) playing.
                    {
                        MainPage.SetPlayButtonAppearance(false); // Set the Play button to display a "play" label, and do 'play' when tapped.
                    }

                    if (PlayQueue.Count > 0) // (this is just defensive coding, it should always be true)
                    {
                        MainPage.SetNowPlaying(PlayQueue[0].DisplayName + " (" + PlayQueue[0].storage.Path + ")");
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Stops the media player (it puts it into the 'hard-stopped' state).
 /// </summary>
 public void Stop()
 {
     ToccataModel.Stop();
 }