Example #1
0
        async void SystemControls_ButtonPressed(SystemMediaTransportControls sender,
                                                SystemMediaTransportControlsButtonPressedEventArgs args)
        {
            switch (args.Button)
            {
            case SystemMediaTransportControlsButton.Play:
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    mediaTimelineController.Start();
                });

                break;

            case SystemMediaTransportControlsButton.Pause:
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    mediaTimelineController.Pause();
                });

                break;

            default:
                break;
            }
        }
Example #2
0
 //播放与暂停按钮
 private void PlayPauseClick(object sender, RoutedEventArgs e)
 {
     if (mediaTimeline != null)
     {
         //暂停之后点击继续或开始
         if (mediaTimeline.State == MediaTimelineControllerState.Paused)
         {
             coverStoryboard.Begin();
             mediaTimeline.Resume();
             playPauseButton.Icon = new SymbolIcon(Symbol.Pause);
         }//播放时暂停
         else if (mediaTimeline.State == MediaTimelineControllerState.Running)
         {
             mediaTimeline.Pause();
             coverStoryboard.Pause();
             playPauseButton.Icon = new SymbolIcon(Symbol.Play);
         }
         else if (mediaTimeline.State == MediaTimelineControllerState.Stalled)
         {
             mediaTimeline.Start();
             coverStoryboard.Begin();
         }
     }
     else
     {
         var messages = new MessageDialog("no file").ShowAsync();
     }
 }
Example #3
0
 private void Pause_Click(object sender, RoutedEventArgs e)
 {
     timer.Stop();
     storyboard.Pause();
     mediaTimelineController.Pause();
     Show_PlayButton();
 }
Example #4
0
 private void Stop()
 {
     mediaTimelineController.Position = TimeSpan.FromSeconds(0);
     mediaTimelineController.Pause();
     PauseButton.Visibility = Visibility.Collapsed;
     PlayButton.Visibility  = Visibility.Visible;
 }
Example #5
0
        //pause the media
        void PauseMedia(object sender, RoutedEventArgs e)
        {
            mediaTimelineController.Pause();//暂停播放

            //图片旋转动画暂停
            EllStoryboard.Pause();

            Start.Visibility = Visibility.Visible;
            Pause.Visibility = Visibility.Collapsed;
        }
Example #6
0
 private void pause_Click(object sender, RoutedEventArgs e)
 {
     timelineController.Pause();
     if (IsAudio())
     {
         EllStoryboard.Pause();
     }
     pause.Visibility = Visibility.Collapsed;
     play.Visibility  = Visibility.Visible;
 }
Example #7
0
 /**
  * MediaPlayerElement Holding Event
  */
 private void MediaPlayerElement_Holding(object sender, HoldingRoutedEventArgs e)
 {
     if (mediaTimelineController.State == MediaTimelineControllerState.Running && e.HoldingState == Windows.UI.Input.HoldingState.Started)
     {
         mediaTimelineController.Pause();
     }
     else if (e.HoldingState == Windows.UI.Input.HoldingState.Started)
     {
         mediaTimelineController.Resume();
     }
 }
        /// <summary>
        /// Sets the content on the MediaPlayers
        /// </summary>
        private void Load_Click(object sender, RoutedEventArgs e)
        {
            EnablePlaybackControls(false);

            // First reset some app logic.
            timelineController.Pause();
            maxNaturalDurationForController = TimeSpan.Zero;
            openedMediaCount = 0;
            foreach (MediaPlayerElement mpe in mediaPlayerElements)
            {
                MainPage.CleanUpMediaPlayerSource(mpe.MediaPlayer);
            }
            timelineController.Position = TimeSpan.Zero;

            // Apply any requested for offset between two videos.
            // Do this before setting the Source on the MediaPlayer to avoid a visible seek on MediaOpened.
            double d = 0.0;

            if (Double.TryParse(mpeCopyOffset.Text, out d))
            {
                mpeCopy.MediaPlayer.TimelineControllerPositionOffset = TimeSpan.FromSeconds(d);
            }
            else
            {
                mpeCopy.MediaPlayer.TimelineControllerPositionOffset = TimeSpan.Zero;
                mpeCopyOffset.Text = "0.0";
            }

            // Set the sources. For this demonstration, we play audio only from the first video.
            Uri uri;

            if (!Uri.TryCreate(mpeMainUri.Text, UriKind.Absolute, out uri))
            {
                rootPage.NotifyUser("Invalid URI for first source.", NotifyType.ErrorMessage);
                return;
            }
            mpeMain.MediaPlayer.Source  = MediaSource.CreateFromUri(uri);
            mpeMain.MediaPlayer.IsMuted = false;

            if (!Uri.TryCreate(mpeCopyUri.Text, UriKind.Absolute, out uri))
            {
                rootPage.NotifyUser("Invalid URI for second source.", NotifyType.ErrorMessage);
                return;
            }
            mpeCopy.MediaPlayer.Source  = MediaSource.CreateFromUri(uri);
            mpeMain.MediaPlayer.IsMuted = true;

            // Enable our custom playback controls now that everything is set up.
            EnablePlaybackControls(true);
        }
Example #9
0
 private async void _mediaPlayer_MediaEnded(MediaPlayer sender, object args)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         _mediaTimelineController.Pause();
         if (PlayingService.IsPlayingSong)
         {
             PlayingService.PlayNextSongs();
         }
         else
         {
             PlayingService.PlayNextRadio();
         }
     });
 }
Example #10
0
 private async void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     if (_duration != TimeSpan.Zero)
     {
         if (_duration <= sender.Position)
         {
             _mediaTimelineController.Pause();
             _mediaTimelineController.Position = TimeSpan.Zero;
         }
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             slide.Value  = sender.Position.TotalSeconds;
             display.Text = (int)sender.Position.TotalSeconds + " / " + _total;
         });
     }
 }
Example #11
0
        public void SetInfoByRef(Song song, bool autoplay = false)
        {
            SongOwned = song;
            if (PlayArea.Height < DefaultHeight && First)
            {
                expandplayarea();
                First = false;
            }
            AlbumCoverImage.Source     = new BitmapImage(new Uri(song.album_url, UriKind.Absolute));
            BackImage.Source           = AlbumCoverImage.Source;
            SongPLayingName.Text       = song.name;
            SongPLayingSingerName.Text = song.singers;

            PlayProcess.Maximum = song.timeint;
            PlayProcess.Value   = 0;

            _mediaTimelineController.Pause();

            WholeTime.Text = "/" + song.interval;
            NowTime.Text   = "0:00";

            PlayAndPause.Icon = new SymbolIcon(Symbol.Play);
            MusicRes          = "shit";                            //symbol
            string Songmid = song.songmid;

            LyricArea.GetLyrics(Songmid);

            var t = new Thread(() => MusicRes = Creeper.GetSongResourseURL(Songmid));

            t.Start();

            // switch song
            if (App.Musicplayer.Source != null)
            {
                App.Musicplayer.Source = null;
                if (App.Musicplayer.PlaybackSession.PlaybackState == MediaPlaybackState.Playing)   //is playing
                {
                    App.Musicplayer.TimelineControllerPositionOffset = TimeSpan.FromSeconds(0);
                }
                PrepareSourse();
            }
            else if (autoplay)
            {
                PrepareSourse();
            }
        }
 private void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     // Pause when playback reaches the maximum duration.
     if (sender.Position > maxNaturalDurationForController)
     {
         sender.Pause();
     }
 }
Example #13
0
 private void ButtonPlay_Click(object sender, RoutedEventArgs e)
 {
     if (timelineController.State == MediaTimelineControllerState.Running || timelineController.State == MediaTimelineControllerState.Stalled)
     {
         timelineController.Pause();
         ButtonPlay.Icon = new SymbolIcon()
         {
             Symbol = Symbol.Play
         };
     }
     else
     {
         timelineController.Resume();
         ButtonPlay.Icon = new SymbolIcon()
         {
             Symbol = Symbol.Pause
         };
     }
 }
Example #14
0
 private void pause_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (_mediaTimelineController.State == MediaTimelineControllerState.Running)
         {
             EllStoryboard.Pause();
             _mediaTimelineController.Pause();
         }
         else
         {
             //EllStoryboard.Resume();
             EllStoryboard.Begin();
             _mediaTimelineController.Resume();
         }
     }
     catch
     {
     }
 }
 private void PlayPause_Click(object sender, RoutedEventArgs e)
 {
     if (timelineController.State == MediaTimelineControllerState.Paused)
     {
         timelineController.Resume();
     }
     else if (timelineController.State == MediaTimelineControllerState.Running)
     {
         timelineController.Pause();
     }
 }
Example #16
0
        private void PlayButtonClick(object sender, RoutedEventArgs e)
        {
            controller.Pause();
            TimeSpan oldtime = controller.Position;

            controller.Duration = null;
            controller.Resume();
            controller.Position = oldtime;
            LrcUpdateTimer.Start();

            UpdateLrcEditBarAutoScroll(true);
        }
Example #17
0
        //</SnippetPlayButtonClick>

        //<SnippetPauseButtonClick>
        private void PauseButton_Click(object sender, RoutedEventArgs e)
        {
            if (_mediaTimelineController.State == MediaTimelineControllerState.Running)
            {
                _mediaTimelineController.Pause();
                _pauseButton.Content = "Resume";
            }
            else
            {
                _mediaTimelineController.Resume();
                _pauseButton.Content = "Pause";
            }
        }
Example #18
0
        private void startOrPause(object sender, RoutedEventArgs e)
        {
            if (timer == null)
            {
                timer          = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(1);
                timer.Tick    += timer_Tick;
                timer.Start();

                EllStoryboard.Begin();              //  图片开始旋转
                mediaTimelineController.Start();

                var pauseIcon = new SymbolIcon(Symbol.Pause);
                startAndPauseButton.Icon  = pauseIcon;
                startAndPauseButton.Label = "暂停";
            }
            else
            {
                if (mediaTimelineController.State == MediaTimelineControllerState.Running)
                {
                    EllStoryboard.Pause();          //  图片暂停旋转
                    mediaTimelineController.Pause();

                    var playIcon = new SymbolIcon(Symbol.Play);
                    startAndPauseButton.Icon  = playIcon;
                    startAndPauseButton.Label = "播放";
                }
                else
                {
                    EllStoryboard.Begin();
                    mediaTimelineController.Resume();

                    var pauseIcon = new SymbolIcon(Symbol.Pause);
                    startAndPauseButton.Icon  = pauseIcon;
                    startAndPauseButton.Label = "暂停";
                }
            }
        }
Example #19
0
        private void AppBarButton_Click_Play(object sender, RoutedEventArgs e)
        {
            if (!isMediaStart)
            {
                isMediaStart = true;
                Debug.WriteLine("start");

                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(1);
                timer.Tick    += TimerClick;
                timer.Start();

                if (timeLine.Value == 0)
                {
                    _mediaTimelineController.Start();
                }
                else
                {
                    _mediaTimelineController.Resume();
                }
                MyPlayBtn.Icon = new SymbolIcon(Symbol.Pause);
                MyStoryBoard.Begin();
            }
            else if (_mediaTimelineController.State == MediaTimelineControllerState.Paused)
            {
                Debug.WriteLine("resume");
                _mediaTimelineController.Resume();
                MyPlayBtn.Icon = new SymbolIcon(Symbol.Pause);
                MyStoryBoard.Resume();
            }
            else if (_mediaTimelineController.State == MediaTimelineControllerState.Running)
            {
                Debug.WriteLine("pause");
                _mediaTimelineController.Pause();
                MyPlayBtn.Icon = new SymbolIcon(Symbol.Play);
                MyStoryBoard.Pause();
            }
        }
        private async void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
        {
            if (Math.Abs(sender.Position.Ticks - LastPositionUpdate.Ticks) > PositionChangeThreshold.Ticks)
            {
                LastPositionUpdate = sender.Position;
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => SeekPosition.Text = $"{(int)LastPositionUpdate.TotalSeconds}");
            }

            // Pause when playback reaches the maximum duration, if there is one.
            if (maxNaturalDurationForController != TimeSpan.Zero && sender.Position > maxNaturalDurationForController)
            {
                sender.Pause();
            }
        }
Example #21
0
 private async void _mediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     if (_duration != TimeSpan.Zero)
     {
         await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             playPos.Value = sender.Position.TotalSeconds;
             TimeSpan left = _duration.Subtract(sender.Position);
             time.Text     = sender.Position.ToString(@"hh\:mm\:ss");
             timeLeft.Text = left.ToString(@"hh\:mm\:ss");
             TimeSpan temp = new TimeSpan(0);
             if (playPos.Value == playPos.Maximum)
             {
                 playPos.Value = 0;
                 media.TimelineController.Position = TimeSpan.FromSeconds(playPos.Value);
                 _mediaTimelineController.Pause();
                 time.Text     = "00:00:00";
                 timeLeft.Text = _duration.ToString(@"hh\:mm\:ss");
                 VisualStateManager.GoToState(this, "Normal", false);
                 myStoryboard.Stop();
             }
         });
     }
 }
        void Timer_Tick(object sender, object e)
        {
            timeLine.Value = ((TimeSpan)_mediaTimelineController.Position).TotalSeconds;
            //textBlock.Text = GenTimeSpanFromSeconds(Math.Round(timeLine.Value));

            lowerTime.Text = GenTimeSpanFromSeconds(Math.Round(RangeSelectorControl.RangeMin));
            upperTime.Text = GenTimeSpanFromSeconds(Math.Round(RangeSelectorControl.RangeMax));
            totalTime.Text = GenTimeSpanFromSeconds(Math.Round(RangeSelectorControl.RangeMax) - Math.Round(RangeSelectorControl.RangeMin));
            if (timeLine.Value == timeLine.Maximum)
            {
                _mediaTimelineController.Position = TimeSpan.FromSeconds(0);
                _mediaTimelineController.Pause();
                EllStoryboard.Stop();
            }
        }
        private async void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
        {
            if (Math.Abs(sender.Position.Ticks - LastPositionUpdate.Ticks) > PositionChangeThreshold.Ticks)
            {
                LastPositionUpdate = sender.Position;
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => SeekPosition.Text = $"{(int)LastPositionUpdate.TotalSeconds}");
            }

            // Pause when playback reaches the maximum duration, if there is one.
            if (maxNaturalDurationForController != TimeSpan.Zero && sender.Position > maxNaturalDurationForController)
            {
                sender.Pause();
            }
        }
Example #24
0
 private void Vm_PauseVideo(object sender, EventArgs e)
 {
     // Pause video when event raised in ViewModel
     _timer.Stop();
     _mediaTimelineController.Pause();
 }
Example #25
0
        /// <summary>
        /// 播放下一首
        /// </summary>
        public static async void PlayNextSongs()
        {
            long willPlayId = 0;

            if (PlayingListBaseObjects == null || PlayingListBaseObjects.Count == 0)
            {
                return;
            }
            int index = PlayingService.PlayingListBaseObjects.IndexOf(PlayingService.PlayingListBaseObjects.FirstOrDefault(p => p.Id == PlayingService.PlayingSong.Id));

            switch (PlayOrderState)
            {
            case PlayOrderStateEnum.顺序播放:
            {
                if (index == PlayingSongList.Count - 1)        //播完,停止
                {
                    MediaTimelineController.Start();
                    MediaTimelineController.Pause();
                    return;
                }
                willPlayId = PlayingService.PlayingListBaseObjects[++index].Id;
            }
            break;

            case PlayOrderStateEnum.列表循环:
            {
                if (index == PlayingSongList.Count - 1)        //播完,回到第一个
                {
                    index = -1;
                }
                willPlayId = PlayingService.PlayingListBaseObjects[++index].Id;
            }
            break;

            case PlayOrderStateEnum.随机播放:
            {
                if (IsPlayedSongContainAllPlayingListSong(PlayedSongId))        //播完,停止
                {
                    MediaTimelineController.Start();
                    MediaTimelineController.Pause();
                    return;
                }
                Random rd = new Random();
                while (true)
                {
                    int i = rd.Next(0, PlayingService.PlayingListBaseObjects.Count - 1);
                    if (!PlayingService.PlayedSongId.Contains(PlayingService.PlayingListBaseObjects[i].Id))
                    {
                        willPlayId = PlayingService.PlayingListBaseObjects[i].Id;
                        break;
                    }
                }
            }
            break;

            case PlayOrderStateEnum.单曲循环:
            {
                MediaTimelineController.Start();
                return;
            }
            }
            for (int i = 0; i < 5; i++)
            {
                if (await ChangePlayingSong(willPlayId, PlayingSongList))
                {
                    break;
                }
            }
            NotifyPopup notifyPopup = new NotifyPopup("多次获取音乐失败,停止播放");
        }
Example #26
0
 private void ButtonPause_Click(object sender, RoutedEventArgs e)
 {
     _mediaTimelineController.Pause();
     AvrilStoryboard.Pause();
 }
 private void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     // Pause when playback reaches the maximum duration.
     if (sender.Position > maxNaturalDurationForController)
     {
         sender.Pause();
     }
 }
Example #28
0
 public void Pause()
 {
     playerTimelineController.Pause();
     Log.WriteLine("[Player]暂停播放 播放进度: " + Position, Level.Info);
 }