Esempio n. 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;
            }
        }
Esempio n. 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();
     }
 }
Esempio n. 3
0
 private void MediaSource_OpenOperationCompleted(MediaSource sender, MediaSourceOpenOperationCompletedEventArgs args)
 {
     Duration = sender.Duration.GetValueOrDefault();
     Log.WriteLine("[Player]载入成功! 音乐时长: " + Duration.ToString(), Level.Info);
     LoadComplete = true;
     playerTimelineController.Start();
 }
Esempio n. 4
0
        public Video()
        {
            this.InitializeComponent();
            var mediaSource = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Video.mp4"));

            mediaSource.OpenOperationCompleted += MediaSource_OpenOperationCompleted;
            mediaPlayer.Source             = mediaSource;
            mediaPlayer.TimelineController = mediaTimelineController;
            mediaPlayerElement.SetMediaPlayer(mediaPlayer);
            mediaTimelineController.Start();
            PlayButton.Visibility = Visibility.Collapsed;
            timer.Tick           += DispatcherTimer_Tick;
            timer.Start();
        }
Esempio n. 5
0
        public MainPage()
        {
            this.InitializeComponent();
            var mediaSource = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/MKJ - Time (口白).mp3"));

            mediaSource.OpenOperationCompleted += MediaSource_OpenOperationCompleted;
            mediaPlayer.Source             = mediaSource;
            mediaPlayer.TimelineController = mediaTimelineController;
            mediaPlayerElement.SetMediaPlayer(mediaPlayer);
            ellStoryBoard.Begin();
            mediaTimelineController.Start();
            PlayButton.Visibility = Visibility.Collapsed;
            timer.Tick           += DispatcherTimer_Tick;
            timer.Start();
        }
Esempio n. 6
0
 private void Start_Click(object sender, RoutedEventArgs e)
 {
     if (duration.TotalSeconds == 0)
     {
         return;
     }
     if (storyboard.GetCurrentState() == Windows.UI.Xaml.Media.Animation.ClockState.Stopped)
     {
         timer.Start();
         storyboard.Begin();
     }
     else
     {
         timer.Start();
         storyboard.Resume();
     }
     if (timeLine.Value == 0)
     {
         mediaTimelineController.Start();
     }
     else
     {
         mediaTimelineController.Resume();
     }
     Show_PauseButton();
 }
Esempio n. 7
0
        private async void UpdateVideo()
        {
            StopVideo();

            if (!(await GetVideoData()))
            {
                return;
            }

            audioPlayer = new MediaPlayer();
            videoPlayer = new MediaPlayer();

            //We use this method so that we can synchronize the audio and video streams
            audioPlayer.Source = MediaSource.CreateFromUri(new Uri(Constants.videoInfo.Audio[0].Url));
            videoPlayer.Source = MediaSource.CreateFromUri(new Uri(Constants.videoInfo.Video[0].Url));

            audioPlayer.CommandManager.IsEnabled = false;
            videoPlayer.CommandManager.IsEnabled = false;

            audioPlayer.TimelineController = timelineController;
            videoPlayer.TimelineController = timelineController;

            viewer.SetMediaPlayer(videoPlayer);

            timelineController.Start();

            //Event that allows us to set the maximum progress bar value and start updating
            videoPlayer.MediaOpened += VideoPlayer_MediaOpened;

            //Update video qualities
            QualityList.ItemsSource = YoutubeItemMethodsStatic.GetVideoQualityList();
        }
Esempio n. 8
0
        private void ButtonPlay_Click(object sender, RoutedEventArgs e)
        {
            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += timer_Tick;
            timer.Start();
            AvrilStoryboard.Begin();
            if (_mediaTimelineController.State == MediaTimelineControllerState.Paused)
            {
                _mediaTimelineController.Resume();
            }
            else
            {
                _mediaTimelineController.Start();
            }
        }
Esempio n. 9
0
        private async void MediaSource_OpenOperationCompleted(MediaSource sender, MediaSourceOpenOperationCompletedEventArgs args)
        {
            _duration = sender.Duration.GetValueOrDefault();

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                // change ui in page
                _mediaTimelineController.Start();
                PlayAndPause.Icon = new SymbolIcon(Symbol.Pause);
            });
        }
Esempio n. 10
0
        private async void openfile_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".mp3");
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".wma");
            openPicker.FileTypeFilter.Add(".mkv");
            file = await openPicker.PickSingleFileAsync();

            try
            {
                if (file != null)
                {
                    var mediaSource = MediaSource.CreateFromStorageFile(file);
                    mediaSource.OpenOperationCompleted += openOperationCompleted;
                    mediaPlayer.Source = mediaSource;
                    Debug.WriteLine(mediaPlayer.AudioCategory);
                    if (!IsAudio())
                    {
                        rotatePic.Visibility = Visibility.Collapsed;
                        EllStoryboard.Stop();
                    }
                    else
                    {
                        rotatePic.Visibility = Visibility.Visible;
                        StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem);

                        if (thumbnail == null)
                        {
                            thumb.ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/1.jpg"));
                        }
                        else
                        {
                            BitmapImage image = new BitmapImage();
                            image.SetSource(thumbnail);
                            thumb.ImageSource = image;
                        }
                    }
                    if (timelineController.State == MediaTimelineControllerState.Running)
                    {
                        timeLine.Value = 0;
                        timelineController.Start();
                    }
                }
            }
            catch
            {
            }
        }
Esempio n. 11
0
        private async void PlayingService_OnPlayingRadioChanged()
        {
            ChangeImage();
            ChangePlayBar(PlayingService.PlayingAlbumBitmapImage, PlayingService.PlayingRadio.Name, PlayingService.PlayingRadio.Dj.Nickname, PlayingService.PlayingRadio.Name, PlayingService.PlayingRadio.MainSong.Duration / 1000);
            if ((Application.Current as App).playingPage != null)
            {
                (Application.Current as App).playingPage.LoadLayout();
            }
            if ((Application.Current as App).compactOverlayPage != null)
            {
                (Application.Current as App).compactOverlayPage.UpdateLayout();
            }
            if (PlayingService.PlayingSongUrlRoot.data.First().url == null)
            {
                NotifyPopup notifyPopup = new NotifyPopup("播放地址错误");
                notifyPopup.Show();
                //跳过当前到下一首
                PlayingService.PlayNextRadio();
                return;
            }
            _mediaSource = await Task.Run(() => MediaSource.CreateFromUri(new Uri(PlayingService.PlayingSongUrlRoot.data.First().url)));

            _mediaSource.OpenOperationCompleted += _mediaSource_OpenOperationCompleted;
            _mediaPlaybackItem  = new MediaPlaybackItem(_mediaSource);
            _mediaPlayer.Source = _mediaPlaybackItem;
            _mediaTimelineController.Start();

            //修改SMTC 显示的元数据
            MediaItemDisplayProperties props = _mediaPlaybackItem.GetDisplayProperties();

            props.Type = Windows.Media.MediaPlaybackType.Music;
            props.MusicProperties.Title  = PlayingService.PlayingRadio.Name;
            props.MusicProperties.Artist = PlayingService.PlayingRadio.Dj.Nickname;
            props.Thumbnail = RandomAccessStreamReference.CreateFromFile(await ApplicationData.Current.LocalFolder.TryGetItemAsync(ConfigService.ImageFilename) as StorageFile);
            _mediaPlaybackItem.ApplyDisplayProperties(props);
        }
Esempio n. 12
0
 private void start_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         DispatcherTimer timer = new DispatcherTimer();
         timer.Interval = TimeSpan.FromSeconds(1);
         timer.Tick    += timer_Tick;
         timer.Start();
         EllStoryboard.Begin();
         _mediaTimelineController.Start();
     }
     catch
     {
     }
 }
Esempio n. 13
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();
            }
        }
Esempio n. 14
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 = "暂停";
                }
            }
        }
Esempio n. 15
0
        //play the media
        void PlayMedia(object sender, RoutedEventArgs e)
        {
            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += Timer;
            timer.Start();
            if (mediaTimelineController.State == MediaTimelineControllerState.Paused)
            {
                mediaTimelineController.Resume();
            }
            else
            {
                mediaTimelineController.Start();//播放加载好的视频文件.
                InitializePropertyValues();
            }

            //图片旋转动画开始
            EllStoryboard.Begin();

            Start.Visibility = Visibility.Collapsed;
            Pause.Visibility = Visibility.Visible;
        }
Esempio n. 16
0
 //<SnippetPlayButtonClick>
 private void PlayButton_Click(object sender, RoutedEventArgs e)
 {
     _mediaTimelineController.Start();
 }
Esempio n. 17
0
 /**
  * Repeat Button
  */
 private void Repeat_Click(object sender, RoutedEventArgs e)
 {
     mediaTimelineController.Start();
 }
Esempio n. 18
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("多次获取音乐失败,停止播放");
        }