Ejemplo n.º 1
0
        public AudioCaptureDialog()
        {
            ResourceLoader res = ResourceLoader.GetForCurrentView();

            this.InitializeComponent();
            this.Title = res.GetString("dlgTitle");
            dlgRecord  = res.GetString("dlgRecord");
            this.SecondaryButtonText = res.GetString("dlgCancel");
            dlgStop   = res.GetString("dlgStop");
            dlgFailed = res.GetString("dlgFailed");
            this.PrimaryButtonText = dlgRecord;
            _player = new MediaPlayer();
            _player.AudioCategory                     = MediaPlayerAudioCategory.Media;
            _mediaTimelineController                  = new MediaTimelineController();
            _player.CommandManager.IsEnabled          = false;
            _mediaTimelineController.PositionChanged += MediaTimelineController_PositionChanged;
            _mediaTimelineController.StateChanged    += MediaTimelineController_StateChanged;
            _player.TimelineController                = _mediaTimelineController;
            _timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            _timer.Tick  += Tick_Tock;
            this.Closing += AudioCaptureDialog_Closing;
        }
Ejemplo n.º 2
0
 public VideosPlayer()
 {
     this.InitializeComponent();
     this.timelineController                  = new MediaTimelineController();
     this.timelineController.Ended           += TimelineController_Ended;
     this.timelineController.PositionChanged += TimelineController_PositionChanged;
 }
Ejemplo n.º 3
0
        private void PlayerTimelineController_PositionChanged(MediaTimelineController sender, object args)
        {
            Position = playerTimelineController.Position;
            if (Position > Duration)
            {
                if (LoadComplete)
                {
                    switch (PlayMode)
                    {
                    case 0:
                        PlayNext();
                        break;

                    case 1:
                        playerTimelineController.Position = TimeSpan.Zero;
                        break;

                    case 2:
                        // 随机播放还没做呢
                        break;
                    }
                }
            }
            PlayerPositionChanged(sender, args);
        }
Ejemplo n.º 4
0
        private void PlayerTimelineController_StateChanged(MediaTimelineController sender, object args)
        {
            // 通知系统我播放状态变了,再执行点其他操作
            switch (sender.State)
            {
            case MediaTimelineControllerState.Running:
                systemMediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Playing;
                break;

            case MediaTimelineControllerState.Paused:
                systemMediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Paused;
                break;

            case MediaTimelineControllerState.Error:
                systemMediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Stopped;
                Log.WriteLine("[Player]播放错误", Level.Error);
                break;

            case MediaTimelineControllerState.Stalled:
                systemMediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Changing;
                Log.WriteLine("[Player]缓冲中... 进度: " + BufferingProgress * 100, Level.Info);
                break;
            }
            PlayerStateChanged(sender, args);
        }
        private void Page_OnLoaded(object sender, RoutedEventArgs e)
        {
            // Create a single MediaTimelineController which will control all of the MediaPlayers.
            timelineController = new MediaTimelineController();

            foreach (MediaPlayerElement mpe in mediaPlayerElements)
            {
                MediaPlayer mp = mpe.MediaPlayer;

                // The CommandManager object must be disabled when attaching a MediaTimelineController.
                // The CommandManager is usually used to route play/pause/seek commands to the MediaPlayer,
                // and apply additional business logic.
                // In a TimelineController scenario, it is important to control the MediaPlayer via a single mechanism.
                mp.CommandManager.IsEnabled = false;
                // Similarly, adding a MediaTimelineController to MediaPlayer will disable media transport controls in the UI.
                mp.TimelineController = timelineController;

                // As noted above, the transport controls are partially disabled due to the MediaTimelineController.
                // To avoid confusing the user, it is best to turn them off.
                mpe.AreTransportControlsEnabled = false;

                // MediaOpened is the right time to find the highest natural duration.
                mp.MediaOpened += MediaPlayer_MediaOpened;
            }

            // Use the MediaTimelineController.StateChanged to control the Play/Pause button content.
            timelineController.StateChanged += MediaTimelineController_StateChanged;

            // Since this is a sample of video on demand, constrain the MediaTimelineController
            // to pause when it reaches the natural end of the last video.
            timelineController.PositionChanged += MediaTimelineController_PositionChanged;

            // We are now set up to load content.
            Load.IsEnabled = true;
        }
        private void Page_OnLoaded(object sender, RoutedEventArgs e)
        {
            // Create a single MediaTimelineController which will control all of the MediaPlayers.
            timelineController = new MediaTimelineController();

            foreach (MediaPlayerElement mpe in mediaPlayerElements)
            {
                MediaPlayer mp = mpe.MediaPlayer;

                // The CommandManager object must be disabled when attaching a MediaTimelineController.
                // The CommandManager is usually used to route play/pause/seek commands to the MediaPlayer,
                // and apply additional business logic.
                // In a TimelineController scenario, it is important to control the MediaPlayer via a single mechanism.
                mp.CommandManager.IsEnabled = false;
                // Similarly, adding a MediaTimelineController to MediaPlayer will disable media transport controls in the UI.
                mp.TimelineController = timelineController;

                // As noted above, the transport controls are partially disabled due to the MediaTimelineController.
                // To avoid confusing the user, it is best to turn them off.
                mpe.AreTransportControlsEnabled = false;

                // MediaOpened is the right time to find the highest natural duration.
                mp.MediaOpened += MediaPlayer_MediaOpened;
            }

            // Use the MediaTimelineController.StateChanged to control the Play/Pause button content.
            timelineController.StateChanged += MediaTimelineController_StateChanged;

            // Since this is a sample of video on demand, constrain the MediaTimelineController
            // to pause when it reaches the natural end of the last video.
            timelineController.PositionChanged += MediaTimelineController_PositionChanged;

            // We are now set up to load content.
            Load.IsEnabled = true;
        }
Ejemplo n.º 7
0
        private async void MediaTimelineController_StateChanged(MediaTimelineController sender, object args)
        {
            switch (sender.State)
            {
            case MediaTimelineControllerState.Running:
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    ppButton.Tag = "pa";
                    smbl.Symbol  = Symbol.Pause;
                });

                break;

            default:
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    ppButton.Tag = "pl";
                    if (!_resume_required)
                    {
                        smbl.Symbol = Symbol.Play;
                    }
                });

                break;
            }
        }
Ejemplo n.º 8
0
        //  private List<movie> movies;

        public MainPage()
        {
            this.InitializeComponent();
            TVs = TVManager.GetTVs();

            InitializeFrostedGlass(btl);
            InitializeFrostedGlass(GlassHost); //毛玻璃
            // movies = MovieManager.GetMovies();

            MediaPlayer             _mediaPlayer             = new MediaPlayer();
            MediaTimelineController _mediaTimelineController = new MediaTimelineController();

            var coreTitleBar = Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().TitleBar;
            var appTitleBar  = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;

            appTitleBar.ButtonBackgroundColor = Colors.Transparent;                   //透明标题栏
            // coreTitleBar.ExtendViewIntoTitleBar = true;
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false; //取消标题栏

            NavigationCacheMode = NavigationCacheMode.Enabled;
            //  SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;


            var displayRequest = new DisplayRequest();

            displayRequest.RequestActive();

            // Window.Current.SetTitleBar(btl); //应用标题栏
        }
 private void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     // Pause when playback reaches the maximum duration.
     if (sender.Position > maxNaturalDurationForController)
     {
         sender.Pause();
     }
 }
Ejemplo n.º 10
0
 private async void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         //slider.Value = Ins_PlayItem.mediaTimelineController.Position.Seconds;
         Ins_PlayItem.ins_PlayItem.StartTime = Ins_PlayItem.mediaTimelineController.Position.TotalSeconds;
         Ins_PlayItem.ins_PlayItem.TotalTime = Ins_PlayItem.mediaPlaybackSession.NaturalDuration.TotalSeconds;
     });
 }
Ejemplo n.º 11
0
        //</SnippetOpenCompleted>


        //<SnippetPositionChanged>
        private async void _mediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
        {
            if (_duration != TimeSpan.Zero)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    _positionSlider.Value = sender.Position.TotalSeconds / (float)_duration.TotalSeconds;
                });
            }
        }
Ejemplo n.º 12
0
 private async void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     if (ViewModel.MediaLength != 0)
     {
         await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             PositionSlider.Value = sender.Position.TotalMilliseconds;
         });
     }
 }
Ejemplo n.º 13
0
        //</SnippetTimelineOffset>


        //<SnippetStateChanged>
        private void _mediaTimelineController_StateChanged(MediaTimelineController sender, object args)
        {
            if (sender.State == MediaTimelineControllerState.Stalled)
            {
                _timelineProgressRing.Visibility = Visibility.Visible;
            }
            else if (sender.State == MediaTimelineControllerState.Stalled && _timelineProgressRing.Visibility == Visibility.Visible)
            {
                _timelineProgressRing.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 14
0
        public PlayerArea()
        {
            this.InitializeComponent();
            DefaultHeight = PlayArea.Height;
            shrinkplayarea();

            //App.Musicplayer.CommandManager.IsEnabled = false;       //千万要注释掉!!!,不然后台不会播放,调声音也不会有反应

            _mediaTimelineController                  = new MediaTimelineController();
            App.Musicplayer.TimelineController        = _mediaTimelineController;
            _mediaTimelineController.PositionChanged += _mediaTimelineController_PositionChanged;
        }
Ejemplo n.º 15
0
        //监控修改播放进度条
        private async void _mediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                isSliderChangedFromAuto = true;
                Slider_play.Value       = sender.Position.TotalSeconds;

                TextBlock_currentTime.Text = OtherHelper.GetDt((int)sender.Position.TotalSeconds);
                if ((Application.Current as App).playingPage != null)
                {
                    (Application.Current as App).playingPage.ChangeLyricPosition(sender.Position.TotalMilliseconds);
                }
            });
        }
        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();
            }
        }
Ejemplo n.º 17
0
 private async void _mediaTimelineController_StateChanged(MediaTimelineController sender, object args)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         if (sender.State == MediaTimelineControllerState.Running)
         {
             playDurationStopwatch.Start();
             SymbolIcon_stopOrPlay.Symbol = Symbol.Pause;
         }
         else
         {
             playDurationStopwatch.Stop();
             SymbolIcon_stopOrPlay.Symbol = Symbol.Play;
         }
     });
 }
Ejemplo n.º 18
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;
         });
     }
 }
Ejemplo n.º 19
0
        //选择文件
        private async void OpenFileClick(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
            fileOpenPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
            fileOpenPicker.FileTypeFilter.Add(".mp4");
            fileOpenPicker.FileTypeFilter.Add(".wmv");
            fileOpenPicker.FileTypeFilter.Add(".wma");
            fileOpenPicker.FileTypeFilter.Add(".mp3");

            StorageFile file = await fileOpenPicker.PickSingleFileAsync();

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

                mediaPlayer = new Windows.Media.Playback.MediaPlayer();
                mediaSource = MediaSource.CreateFromStream(stream, file.ContentType);
                title.Text  = file.Name;
            }
            else
            {
                mediaPlayer = new Windows.Media.Playback.MediaPlayer();
                mediaSource = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/week4.mp4"));
                title.Text  = "week4";
            }
            mediaSource.OpenOperationCompleted += MediaSourceOpenOperationCompleted;
            mediaPlayer.Source = mediaSource;
            mediaPlayerElement.SetMediaPlayer(mediaPlayer);
            mediaTimeline = new MediaTimelineController();
            mediaPlayer.CommandManager.IsEnabled = false;
            mediaPlayer.TimelineController       = mediaTimeline;
            mediaTimeline.IsLoopingEnabled       = true;
            mediaTimeline.PositionChanged       += MediaTimelinePositionChanged;
            if (file != null && file.ContentType == "audio/mpeg")
            {
                cover.Visibility           = Visibility.Visible;
                fullScreenButton.IsEnabled = false;
            }
            else
            {
                cover.Visibility           = Visibility.Collapsed;
                fullScreenButton.IsEnabled = true;
            }
            RestartClick(sender, e);
        }
Ejemplo n.º 20
0
        public MainPage()
        {
            InitializeComponent();
            media = new MediaPlayer();
            var mediaSource = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/song.mp3"));

            mediaSource.OpenOperationCompleted += MediaSource_OpenOperationCompleted;
            media.Volume             = 50;
            _mediaTimelineController = new MediaTimelineController();
            _mediaTimelineController.PositionChanged += _mediaTimelineController_PositionChanged;
            media.CommandManager.IsEnabled            = false;
            media.TimelineController = _mediaTimelineController;
            time.Text     = "00:00:00";
            timeLeft.Text = "00:00:00";
            media.Source  = mediaSource;
            player.SetMediaPlayer(media);
            volumeSlider.Value = 50;
        }
Ejemplo n.º 21
0
 public MainPage()
 {
     this.InitializeComponent();
     this.speed.ManipulationMode              = ManipulationModes.Rotate;
     this.volume.ManipulationMode             = ManipulationModes.TranslateX;
     this.mediaPlayerElement.ManipulationMode = ManipulationModes.Scale | ManipulationModes.TranslateInertia | ManipulationModes.TranslateX | ManipulationModes.TranslateY;
     mediaPlayer                              = new MediaPlayer();
     mediaTimelineController                  = new MediaTimelineController();
     mediaPlayerElement.Source                = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/sample.mp4"));
     mediaPlayer                              = mediaPlayerElement.MediaPlayer;
     mediaPlayer.CommandManager.IsEnabled     = false;
     mediaPlayer.TimelineController           = mediaTimelineController;
     mediaTimelineController.IsLoopingEnabled = true;
     mediaPlayer.Volume                       = 0.5;
     InitializePropertiesAsync();
     OnResize();
     SizeChanged = new WindowSizeChangedEventHandler((o, e) => OnResize());
     Window.Current.SizeChanged += SizeChanged;
 }
        private async void MediaTimelineController_StateChanged(MediaTimelineController sender, object args)
        {
            // Update the Play/Pause button based on the new state.
            Symbol newSymbol;

            switch (sender.State)
            {
            case MediaTimelineControllerState.Paused:
                newSymbol = Symbol.Play;
                break;

            case MediaTimelineControllerState.Running:
                newSymbol = Symbol.Pause;
                break;

            default:
                return;
            }
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => PlayPauseIcon.Symbol = newSymbol);
        }
Ejemplo n.º 23
0
        private async void MediaTimelineController_StateChanged(MediaTimelineController sender, object args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                switch (Ins_PlayItem.mediaTimelineController.State.ToString())
                {
                case "Running":
                    Status_Btn.Tag = "pause";
                    Ins_PlayItem.ins_PlayItem.Status = "pause";
                    Status_Symbol.Symbol             = Symbol.Pause;
                    break;

                case "Paused":
                    Status_Btn.Tag = "resume";
                    Ins_PlayItem.ins_PlayItem.Status = "resume";
                    Status_Symbol.Symbol             = Symbol.Play;
                    break;
                }
            });
        }
Ejemplo n.º 24
0
        public Stopwatch playDurationStopwatch;            //当前歌曲播放时长
        public MainPage()
        {
            _mediaPlayer    = new MediaPlayer();
            backgroundBrush = new SolidColorBrush(Colors.Black);
            this.InitializeComponent();
            this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
            Loaded += MainPage_Loaded;
            (Application.Current as App).myMainPage = this;
            _mediaTimelineController = PlayingService.MediaTimelineController;
            _mediaTimelineController.PositionChanged += _mediaTimelineController_PositionChanged;
            _mediaTimelineController.StateChanged    += _mediaTimelineController_StateChanged;
            _mediaPlayer.TimelineController           = _mediaTimelineController;
            _mediaPlayer.MediaEnded    += _mediaPlayer_MediaEnded;
            _mediaPlayer.SourceChanged += _mediaPlayer_SourceChanged;


            //接管系统播放音频控制
            _mediaPlayer.CommandManager.NextBehavior.EnablingRule     = MediaCommandEnablingRule.Always;
            _mediaPlayer.CommandManager.PreviousBehavior.EnablingRule = MediaCommandEnablingRule.Always;
            _mediaPlayer.CommandManager.PreviousReceived += CommandManager_PreviousReceived;
            _mediaPlayer.CommandManager.NextReceived     += CommandManager_NextReceived;
            mainImageBrush        = new ImageBrush();
            mainSolidColorBrush   = new SolidColorBrush(Colors.White);
            playDurationStopwatch = PlayingService.PlayDurationStopwatch;

            PlayingService.PlayingSongList        = new List <SongsItem>();
            PlayingService.PlayingRadioList       = new List <RadioSongItem>();
            PlayingService.OnPlayingSongChanged  += PlayingService_OnPlayingSongChanged;
            PlayingService.OnPlayingRadioChanged += PlayingService_OnPlayingRadioChanged;
            GetSetting();

            //设置标题栏
            var tiWtleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;

            tiWtleBar.BackgroundColor               = Colors.Transparent;
            tiWtleBar.ButtonBackgroundColor         = Colors.Transparent;
            tiWtleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            tiWtleBar.ButtonHoverBackgroundColor    = Colors.LightGray;
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            Window.Current.SetTitleBar(MyTitleBar);
        }
Ejemplo n.º 25
0
        //</SnippetDeclareMediaTimelineController>

        private void SetTimelineControllerButton_Click(object sender, RoutedEventArgs e)
        {
            //<SnippetSetTimelineController>
            mediaPlayer        = new MediaPlayer();
            mediaPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/example_video.mkv"));
            _mediaPlayerElement.SetMediaPlayer(mediaPlayer);


            _mediaPlayer2        = new MediaPlayer();
            _mediaPlayer2.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/example_video_2.mkv"));
            _mediaPlayerElement2.SetMediaPlayer(_mediaPlayer2);

            _mediaTimelineController = new MediaTimelineController();

            mediaPlayer.CommandManager.IsEnabled = false;
            mediaPlayer.TimelineController       = _mediaTimelineController;

            _mediaPlayer2.CommandManager.IsEnabled = false;
            _mediaPlayer2.TimelineController       = _mediaTimelineController;
            //</SnippetSetTimelineController>
        }
Ejemplo n.º 26
0
        //</SnippetDeclareMediaTimelineController>

        public void SetTimelineController()
        {
            //<SnippetSetTimelineController>
            _mediaPlayer        = new MediaPlayer();
            _mediaPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/example_video.mkv"));
            _mediaPlayerElement.SetMediaPlayer(_mediaPlayer);


            _mediaPlayer2        = new MediaPlayer();
            _mediaPlayer2.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/example_video_2.mkv"));
            _mediaPlayerElement2.SetMediaPlayer(_mediaPlayer2);

            _mediaTimelineController = new MediaTimelineController();

            _mediaPlayer.CommandManager.IsEnabled = false;
            _mediaPlayer.TimelineController       = _mediaTimelineController;

            _mediaPlayer2.CommandManager.IsEnabled = false;
            _mediaPlayer2.TimelineController       = _mediaTimelineController;
            //</SnippetSetTimelineController>
        }
Ejemplo n.º 27
0
        private async void ViewModelPositionChange(MediaTimelineController sender, object args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                try
                {
                    timeLine.Value = sender.Position.TotalSeconds;
                    if (timeLine.Value == timeLine.Maximum)
                    {
                        if (timeLine.Value != 0 && timeLine.Maximum != 0)
                        {
                            Pause();
                        }
                    }
                }

                catch (Exception)
                {
                    throw new Exception("111");
                }
            });
        }
Ejemplo n.º 28
0
 //让slider的进度与播放进度一致
 private async void MediaTimelinePositionChanged(MediaTimelineController sender, object args)
 {
     if (timeSpan != TimeSpan.Zero)
     {
         await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             if (mediaSlider.Maximum < sender.Position.TotalSeconds)
             {
                 mediaTimeline.Pause();
                 int i = (int)sender.Position.TotalSeconds;
                 recordSeconds.Text = i.ToString() + "s";
             }
             else
             {
                 mediaSlider.Value  = sender.Position.TotalSeconds;
                 mediaSlider1.Value = sender.Position.TotalSeconds;
                 int i = (int)sender.Position.TotalSeconds;
                 recordSeconds.Text = i.ToString() + "s";
             }
         });
     }
 }
Ejemplo n.º 29
0
        private void InitializeNAudio()
        {
            player = new MediaPlayer();


            player.PlaybackSession.NaturalDurationChanged += async(s, o) =>
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                {
                    ProgressSlider.Maximum = s.NaturalDuration.TotalMilliseconds;
                });
            };

            player.Volume = VolumeSlider.Value / 100;

            /*
             * player.VolumeChanged += (mp, s) =>
             * {
             *  //VolumeSlider.Value = mp.Volume * 100;
             * };
             */
            controller = player.TimelineController = new Windows.Media.MediaTimelineController();
        }
Ejemplo n.º 30
0
 private async void _mediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     if (_duration != TimeSpan.Zero && !ISMoving)
     {
         await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             int nowtime = Convert.ToInt32(sender.Position.TotalSeconds);
             if (nowtime % 60 > 9)
             {
                 NowTime.Text = (nowtime / 60).ToString() + ":" + (nowtime % 60).ToString();
             }
             else
             {
                 NowTime.Text = (nowtime / 60).ToString() + ":0" + (nowtime % 60).ToString();
             }
             PlayProcess.Value = nowtime;
             LyricArea.Settime(Convert.ToDouble(nowtime));
             if (nowtime == PlayProcess.Maximum)   //play complete
             {
                 MusicListSet(Playingid + 1);
             }
         });
     }
 }
Ejemplo n.º 31
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();
             }
         });
     }
 }
 private void MediaTimelineController_PositionChanged(MediaTimelineController sender, object args)
 {
     // Pause when playback reaches the maximum duration.
     if (sender.Position > maxNaturalDurationForController)
     {
         sender.Pause();
     }
 }
        private async void MediaTimelineController_StateChanged(MediaTimelineController sender, object args)
        {
            // Update the Play/Pause button based on the new state.
            Symbol newSymbol;
            switch (sender.State)
            {
                case MediaTimelineControllerState.Paused:
                    newSymbol = Symbol.Play;
                    break;

                case MediaTimelineControllerState.Running:
                    newSymbol = Symbol.Pause;
                    break;

                default:
                    return;
            }
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => PlayPauseIcon.Symbol = newSymbol);
        }
        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();
            }
        }