Пример #1
0
        private async void NextTrackButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            try
            {
                HideToLeftAnimation();

                if (!(await PlaybackActionHelper.NextTrack()))
                {
                    showFromLeftStoryboard.Begin();
                    animationState = AnimationState.None;
                    ViewModel.ProgressRingActive = false;
                    return;
                }

                ViewModel.NextButtonEnabled = false;
                await Task.Delay(1000);

                await PlayStatusTracker.RefreshPlayStatus();

                ViewModel.NextButtonEnabled = true;
            }
            catch (UnauthorizedAccessException)
            {
                UnauthorizedHelper.OnUnauthorizedError();
            }
        }
Пример #2
0
        private async void PlayButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            try
            {
                ViewModel.IsPlaying = true;
                ViewModel.PlayPauseButtonEnabled = false;
                timer.Stop();

                // This delay is a workaround for PlayPauseButtonEnabled to
                // update the newly appeared UI. Otherwize it appears after
                // running PlaybackActionHelper.Play().
                await Task.Delay(100);

                if (await PlaybackActionHelper.Play())
                {
                    await Task.Delay(1000);

                    await PlayStatusTracker.RefreshPlayStatus();

                    ViewModel.PlayPauseButtonEnabled = true;
                }
                else
                {
                    ViewModel.IsPlaying = false;
                    ViewModel.PlayPauseButtonEnabled = true;

                    await PlayStatusTracker.RefreshPlayStatus();
                }
            }
            catch (UnauthorizedAccessException)
            {
                UnauthorizedHelper.OnUnauthorizedError();
            }
            finally
            {
                ViewModel.PlayPauseButtonEnabled = true;
                if (!timer.IsEnabled)
                {
                    timer.Start();
                }
            }
        }
Пример #3
0
        private async void SystemControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs e)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                var mediaControls = SystemMediaTransportControls.GetForCurrentView();

                try
                {
                    switch (e.Button)
                    {
                    case SystemMediaTransportControlsButton.Play:
                        if (await PlaybackActionHelper.Play())
                        {
                            mediaControls.PlaybackStatus = MediaPlaybackStatus.Playing;
                        }

                        break;

                    case SystemMediaTransportControlsButton.Pause:
                        if (await PlaybackActionHelper.Pause())
                        {
                            mediaControls.PlaybackStatus = MediaPlaybackStatus.Paused;
                        }

                        break;

                    case SystemMediaTransportControlsButton.Stop:
                        if (await PlaybackActionHelper.Pause())
                        {
                            mediaControls.PlaybackStatus = MediaPlaybackStatus.Paused;
                        }

                        break;

                    case SystemMediaTransportControlsButton.Next:
                        if (await PlaybackActionHelper.NextTrack())
                        {
                            compactOverlayView?.PlayChangeTrackAnimation(reverse: false);
                        }

                        break;

                    case SystemMediaTransportControlsButton.Previous:
                        if (await PlaybackActionHelper.PreviousTrack())
                        {
                            compactOverlayView?.PlayChangeTrackAnimation(reverse: true);
                        }

                        // Necessary for progress bar update, in case 'previous' command goes to
                        // the beginning of the same track.
                        await Task.Delay(500);
                        await PlayStatusTracker.RefreshPlayStatus();

                        break;
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    UnauthorizedHelper.OnUnauthorizedError();
                }
            });
        }