コード例 #1
0
        private async void ChooseFile(object sender, RoutedEventArgs e)
        {
            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

            openPicker.FileTypeFilter.Add(".wmv");
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".wma");
            openPicker.FileTypeFilter.Add(".mp3");

            var file = await openPicker.PickSingleFileAsync();

            if (file != null)
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                mediaPlayer.SetSource(stream, file.ContentType);
                this.Pause(mediaPlayer, null);
                if (file.ContentType.StartsWith("video"))
                {
                    this.ellipse.Visibility     = Visibility.Collapsed;
                    this.mediaPlayer.Visibility = Visibility.Visible;
                }
                else
                {
                    this.ellipse.Visibility     = Visibility.Visible;
                    this.mediaPlayer.Visibility = Visibility.Collapsed;
                }
                EllStoryboard.Stop();
            }
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: ktpm489/mediaPlayer
 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 = "Pause";
     }
     else
     {
         if (mediaTimelineController.State == MediaTimelineControllerState.Running)
         {
             EllStoryboard.Pause();
             mediaTimelineController.Pause();
             var playIcon = new SymbolIcon(Symbol.Play);
             startAndPauseButton.Icon  = playIcon;
             startAndPauseButton.Label = "Play";
         }
         else
         {
             EllStoryboard.Begin();
             mediaTimelineController.Resume();
             var pauseIcon = new SymbolIcon(Symbol.Pause);
             startAndPauseButton.Icon  = pauseIcon;
             startAndPauseButton.Label = "Pause";
         }
     }
 }
コード例 #3
0
 public void DisplayButton_Click(object sender, RoutedEventArgs e)
 {
     if (mediaPlayer.CurrentState == MediaPlayerState.Paused || mediaPlayer.CurrentState == MediaPlayerState.Stopped)
     {
         DispatcherTimer timer = new DispatcherTimer();
         timer.Interval = TimeSpan.FromSeconds(1);
         timer.Tick    += timer_Tick;
         timer.Start();
         EllStoryboard.Begin();
         innerEllStoryboard.Begin();
         switchOn.Begin();
         mediaPlayer.Play();
         DisplayButton.Label = "暂停";
         DisplayButton.Icon  = new SymbolIcon(Symbol.Pause);
     }
     else if (mediaPlayer.CurrentState == MediaPlayerState.Playing)
     {
         EllStoryboard.Pause();
         innerEllStoryboard.Pause();
         switchOff.Begin();
         mediaPlayer.Pause();
         DisplayButton.Label = "播放";
         DisplayButton.Icon  = new SymbolIcon(Symbol.Play);
     }
 }
コード例 #4
0
 private void Stop(object sender, RoutedEventArgs e)
 {
     PlayButton.Visibility  = Visibility.Visible;
     PauseButton.Visibility = Visibility.Collapsed;
     mediaPlayer.Stop();
     EllStoryboard.Stop();
 }
コード例 #5
0
 private async void Player_MediaOpened(MediaPlayer sender, object args)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         MusicTime = sender.PlaybackSession.NaturalDuration.ToString(@"mm\:ss");
         EllStoryboard.Begin();
     });
 }
コード例 #6
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("DetailBackAnimation", GridBack);

            EllStoryboard.Stop();
            RollTicker.Stop();
            BackBlurTicker.Stop();
            BackBlurBrush.Amount = 0;
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: lcccyb/homework
 void timer_Tick(object sender, object e)
 {
     timeLine.Value = ((TimeSpan)_mediaTimelineController.Position).TotalSeconds;
     if (timeLine.Value == timeLine.Maximum)
     {
         _mediaTimelineController.Position = TimeSpan.FromSeconds(0);
         _mediaTimelineController.Pause();
         EllStoryboard.Stop();
     }
 }
コード例 #8
0
ファイル: MainPage.xaml.cs プロジェクト: Liu-YT/MOSAD
        //pause the media
        void PauseMedia(object sender, RoutedEventArgs e)
        {
            mediaTimelineController.Pause();//暂停播放

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

            Start.Visibility = Visibility.Visible;
            Pause.Visibility = Visibility.Collapsed;
        }
コード例 #9
0
ファイル: MainPage.xaml.cs プロジェクト: ktpm489/mediaPlayer
        private void stopMediaPlayer()
        {
            EllStoryboard.Stop();
            mediaTimelineController.Position = TimeSpan.FromSeconds(0);
            mediaTimelineController.Pause();
            var playIcon = new SymbolIcon(Symbol.Play);

            startAndPauseButton.Icon  = playIcon;
            startAndPauseButton.Label = "Play";
        }
コード例 #10
0
ファイル: MainPage.xaml.cs プロジェクト: liuwd8/uwp
 private void pause_Click(object sender, RoutedEventArgs e)
 {
     timelineController.Pause();
     if (IsAudio())
     {
         EllStoryboard.Pause();
     }
     pause.Visibility = Visibility.Collapsed;
     play.Visibility  = Visibility.Visible;
 }
コード例 #11
0
 public void StopButton_Click(object sender, RoutedEventArgs e)
 {
     EllStoryboard.Stop();
     innerEllStoryboard.Stop();
     switchOn.Stop();
     mediaPlayer.Position = TimeSpan.FromSeconds(0);
     DisplayButton.Label  = "播放";
     DisplayButton.Icon   = new SymbolIcon(Symbol.Play);
     mediaPlayer.Pause();
 }
コード例 #12
0
ファイル: MainPage.xaml.cs プロジェクト: liuwd8/uwp
 private void TimerTick(object sender, object e)
 {
     timeLine.Value   = ((TimeSpan)timelineController.Position).TotalSeconds;
     displayTime.Text = timelineController.Position.ToString().Substring(0, 8) + str;
     if (timeLine.Value == timeLine.Maximum)
     {
         timelineController.Position = TimeSpan.FromSeconds(0);
         timelineController.Pause();
         EllStoryboard.Stop();
     }
 }
コード例 #13
0
 private void SelectedMusicItemChanged()
 {
     EllStoryboard.Stop();
     innerEllStoryboard.Stop();
     switchOff.Begin();
     mediaPlayer.Pause();
     DisplayButton.Label = "播放";
     DisplayButton.Icon  = new SymbolIcon(Symbol.Play);
     mediaPlayer.Source  = MediaSource.CreateFromStorageFile(viewModel.SelectedMusicItem.File);
     getLyric(viewModel.SelectedMusicItem.Title, viewModel.SelectedMusicItem.Artist);
     Bindings.Update();
 }
コード例 #14
0
ファイル: MainPage.xaml.cs プロジェクト: Liu-YT/MOSAD
        // Stop the media.
        void StopMedia(object sender, RoutedEventArgs e)
        {
            //停止播放,再次播放会从头开始
            mediaTimelineController.Position = TimeSpan.FromSeconds(0);
            mediaTimelineController.Pause();

            Start.Visibility = Visibility.Visible;
            Pause.Visibility = Visibility.Collapsed;

            //图片旋转动画结束
            EllStoryboard.Stop();
        }
コード例 #15
0
ファイル: MainPage.xaml.cs プロジェクト: lcccyb/homework
 private void stop_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         _mediaTimelineController.Position = TimeSpan.FromSeconds(0);
         _mediaTimelineController.Pause();
         EllStoryboard.Stop();
     }
     catch
     {
     }
 }
コード例 #16
0
ファイル: MainPage.xaml.cs プロジェクト: liuwd8/uwp
        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
            {
            }
        }
コード例 #17
0
 private void CustomMTC_PlayPause(object sender, EventArgs e)
 {
     if (mpe.CurrentState == MediaElementState.Playing)
     {
         EllStoryboard.Pause();
         dispatcherTimer.Stop();
     }
     else if (mpe.CurrentState == MediaElementState.Paused || mpe.CurrentState == MediaElementState.Stopped)
     {
         EllStoryboard.Resume();
         dispatcherTimer.Start();
     }
 }
コード例 #18
0
ファイル: MainPage.xaml.cs プロジェクト: Liu-YT/MOSAD
 void Timer(object sender, object e)
 {
     nowTime.Text   = mediaPlayer.PlaybackSession.Position.ToString().Substring(0, 8);
     timeLine.Value = ((TimeSpan)mediaTimelineController.Position).TotalSeconds;
     if (timeLine.Value == timeLine.Maximum)
     {
         mediaTimelineController.Position = TimeSpan.FromSeconds(0);
         mediaTimelineController.Pause();
         EllStoryboard.Stop();
         Pause.Visibility = Visibility.Collapsed;
         Start.Visibility = Visibility.Visible;
     }
 }
コード例 #19
0
ファイル: MainPage.xaml.cs プロジェクト: lcccyb/homework
 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
     {
     }
 }
コード例 #20
0
        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();
            }
        }
コード例 #21
0
        public MediaPlayerPage()
        {
            InitializeComponent();
            // 处理旋转盘片的显示和隐藏
            mpe.MediaOpened += async(Media, o) => {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () => {
                    mpe.TransportControls.IsStopEnabled = true;
                    if (mpe.NaturalVideoHeight > 0)
                    {
                        DisplayDisk = false;
                    }
                    else
                    {
                        DisplayDisk = true;
                    }

                    MediaElement media        = Media as MediaElement;
                    String allTime            = media.NaturalDuration.TimeSpan.ToString();
                    TimeRemainingElement.Text = allTime.Substring(0, allTime.IndexOf('.'));
                    ProgressSlider.Maximum    = media.NaturalDuration.TimeSpan.TotalSeconds;

                    ProgressSlider.IsEnabled = true;
                    dispatcherTimer          = new DispatcherTimer();
                    dispatcherTimer.Tick    += dispatcherTimer_Tick;
                    dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
                    dispatcherTimer.Start();
                    PlayPauseSymbol.Symbol = Symbol.Pause;
                });
            };


            mpe.MediaEnded += async(m, o) => {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () => {
                    EllStoryboard.Stop();
                    EllStoryboard.Begin();
                    EllStoryboard.Pause();
                    dispatcherTimer.Stop();
                    PlayPauseSymbol.Symbol  = Symbol.Play;
                    TimeElapsedElement.Text = "00:00:00";
                    ProgressSlider.Value    = 0;
                });
            };

            ProgressSlider.ValueChanged += MediaSlider_ValueChanged;
        }
コード例 #22
0
        private void StopButton_Click(object sender, RoutedEventArgs e)
        {
            if (mpe.CurrentState == MediaElementState.Playing)
            {
                EllStoryboard.Stop();
                EllStoryboard.Begin();
                EllStoryboard.Pause();

                TimeElapsedElement.Text = "00:00:00";
                ProgressSlider.Value    = 0;

                dispatcherTimer.Stop();

                mpe.Stop();
                PlayPauseSymbol.Symbol = Symbol.Play;
            }
        }
コード例 #23
0
 private void PlayPauseButton_Click(object sender, RoutedEventArgs e)
 {
     if (mpe.CurrentState == MediaElementState.Playing)
     {
         // 停止播放
         PlayPauseSymbol.Symbol = Symbol.Play;
         mpe.Pause();
         EllStoryboard.Pause();
         dispatcherTimer.Stop();
     }
     else if (mpe.CurrentState == MediaElementState.Paused || mpe.CurrentState == MediaElementState.Stopped)
     {
         // 继续播放
         PlayPauseSymbol.Symbol = Symbol.Pause;
         mpe.Play();
         EllStoryboard.Resume();
         dispatcherTimer.Start();
     }
 }
コード例 #24
0
        void timer_Tick(object sender, object e)
        {
            Display_ProcessBar.Value = ((TimeSpan)mediaPlayer.Position).TotalSeconds;
            if (Display_ProcessBar.Value == Display_ProcessBar.Maximum)
            {
                mediaPlayer.Position = TimeSpan.FromSeconds(0);
                if ((string)DisplayOrderButton.Tag == "Circle")
                {
                    EllStoryboard.Begin();
                    innerEllStoryboard.Begin();
                    switchOn.Begin();
                    mediaPlayer.Play();
                    DisplayButton.Label = "暂停";
                    DisplayButton.Icon  = new SymbolIcon(Symbol.Pause);
                }
                else
                {
                    mediaPlayer.Pause();
                    EllStoryboard.Stop();
                    switchOff.Begin();
                    innerEllStoryboard.Stop();
                    DisplayButton.Label = "播放";
                    DisplayButton.Icon  = new SymbolIcon(Symbol.Play);
                }
            }
            String time;
            int    minute  = ((int)Display_ProcessBar.Value) / 60;
            int    second  = ((int)Display_ProcessBar.Value) - minute * 60;
            string minutes = minute.ToString();
            string seconds = second.ToString();

            if (minute < 10)
            {
                minutes = "0" + minute.ToString();
            }
            if (second < 10)
            {
                seconds = "0" + second.ToString();
            }
            time             = minutes + ":" + seconds;
            CurrentTime.Text = time;
        }
コード例 #25
0
        private async void PlaybackSession_PlaybackStateChanged(MediaPlaybackSession sender, object args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                switch (State)
                {
                case MediaPlaybackState.Playing:
                    EllStoryboard.Resume();
                    break;

                case MediaPlaybackState.Paused:
                    EllStoryboard.Pause();
                    break;

                case MediaPlaybackState.None:
                    EllStoryboard.Stop();
                    break;
                }
            });
        }
コード例 #26
0
ファイル: MainPage.xaml.cs プロジェクト: liuwd8/uwp
 private void play_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         DispatcherTimer timer = new DispatcherTimer();
         timer.Interval = TimeSpan.FromSeconds(1);
         timer.Tick    += TimerTick;
         timer.Start();
         if (IsAudio())
         {
             EllStoryboard.Begin();
         }
         timelineController.Resume();
         play.Visibility  = Visibility.Collapsed;
         pause.Visibility = Visibility.Visible;
     }
     catch
     {
     }
 }
コード例 #27
0
ファイル: MainPage.xaml.cs プロジェクト: lcccyb/homework
 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
     {
     }
 }
コード例 #28
0
 private void Start_pause_Click(object sender, RoutedEventArgs e)
 {
     if (_mediaTimelineController.State == MediaTimelineControllerState.Running)
     {
         EllStoryboard.Pause();
         this._mediaTimelineController.Pause();
         start_pause.Icon = new SymbolIcon(Symbol.Play);
     }
     else
     {
         if (_mediaTimelineController.Position.TotalSeconds < RangeSelectorControl.RangeMin)
         {
             this._mediaTimelineController.Position = TimeSpan.FromSeconds(RangeSelectorControl.RangeMin);
             EllStoryboard.BeginTime = this._mediaTimelineController.Position;
         }
         EllStoryboard.Begin();
         this._mediaTimelineController.Resume();
         start_pause.Icon = new SymbolIcon(Symbol.Pause);
     }
 }
コード例 #29
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("ToDetailAnimation");
                if (animation != null)
                {
                    animation.TryStart(GridBack);
                }
            }
            catch (Exception) { }

            BackBlurBrush.Amount = 0;
            BackBlurTicker.Start();

            if (MusicPage.ThisPage.MediaControl.MediaPlayer.PlaybackSession.PlaybackState == MediaPlaybackState.Playing)
            {
                EllStoryboard.Begin();
                RollTicker.Start();
            }
        }
コード例 #30
0
        private async void OpenFileButton_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.MusicLibrary
            };

            string[] type = { ".mp3", ".mp4", ".avi", ".wmv", ".rmvb", ".mpeg", ".wma" };
            foreach (string s in type)
            {
                picker.FileTypeFilter.Add(s);
            }
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                mpe.AutoPlay = true;
                //get the stream from the storage file
                var mediaStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                //set the source to the video stream
                mpe.SetSource(mediaStream, file.ContentType);
                EllStoryboard.Begin();
                // MediaSource.CreateFromStorageFile(file);
                JsonObject res = await Services.MusicService.SearchSong(file.Name);

                string     songId   = Services.MusicService.GetSongIdFromSearch(res);
                JsonObject songData = await Services.MusicService.GetSongDetail(songId);

                string url        = Services.MusicService.GetAlbumImageFromSong(songData);
                string AlbumTitle = Services.MusicService.GetAlbumTitleFromSong(songData);
                DiskImage.ImageSource = new BitmapImage(new Uri(url));


                TitleText.Text = file.Name;
                AlbumText.Text = AlbumTitle;
                EllStoryboard.Resume();
            }
        }