private void Image_PointerPressed(object sender, PointerRoutedEventArgs e) { if (MediaControl.MediaPlayer.Source == null) { return; } PictureBackup.Visibility = Visibility.Visible; ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("ToDetailAnimation", PicturePlaying).Configuration = new BasicConnectedAnimationConfiguration(); ConnectedAnimationService.GetForCurrentView().DefaultDuration = TimeSpan.FromMilliseconds(400); MusicNav.Navigate(typeof(MusicDetail)); }
private async void MusicPage_Loaded(object sender, RoutedEventArgs e) { MediaControl.MediaPlayer.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged; MediaControl.MediaPlayer.AudioCategory = MediaPlayerAudioCategory.Media; //启用实时播放会增加资源占用但同时避免了进度条刷新慢和声音卡顿的问题 MediaControl.MediaPlayer.RealTimePlayback = true; MediaControl.MediaPlayer.PlaybackSession.BufferingStarted += PlaybackSession_BufferingStarted; /* * 在此处放置异步看起来是不必要的,可能会因为不必要的异步造成开销过大 * 但不然,原因是异步使得MusicPage_Loaded函数能够增加async关键字 * async和void配合使用时,调用方将不会等待该函数执行完即返回 * 同时由于MusicPage_Loaded执行很多初始化操作,若等待MusicPage_Loaded执行完 * 则会导致进入音乐模块时出现较长的卡顿时间,但其实进入音乐模块不必等待MusicPage_Loaded执行完毕 */ await Task.Run(() => { MediaPlayList.FavouriteSongList.CurrentItemChanged += MediaList_CurrentItemChanged; MediaPlayList.SingerHotSongList.CurrentItemChanged += SingerHotSongList_CurrentItemChanged; MediaPlayList.AlbumSongList.CurrentItemChanged += AlbumSongList_CurrentItemChanged; }); MusicNav.Navigate(typeof(MusicList), MusicNav, new DrillInNavigationTransitionInfo()); ModeNotification = new PlayModeNotification(); VoiceRec.PlayCommanded += (s, m) => { MediaControl.MediaPlayer.Play(); }; VoiceRec.PauseCommanded += (s, m) => { MediaControl.MediaPlayer.Pause(); }; VoiceRec.MusicChoiceCommanded += (s, SongName) => { for (int i = 0; i < MusicList.ThisPage.FavouriteMusicCollection.Count; i++) { string Music = string.Empty; if (MusicList.ThisPage.FavouriteMusicCollection[i].Music.EndsWith(' ')) { Music = MusicList.ThisPage.FavouriteMusicCollection[i].Music.Remove(MusicList.ThisPage.FavouriteMusicCollection[i].Music.Length - 1); } else { Music = MusicList.ThisPage.FavouriteMusicCollection[i].Music; } if (Music == SongName) { if (MediaControl.MediaPlayer.Source != MediaPlayList.FavouriteSongList) { MediaControl.MediaPlayer.Source = MediaPlayList.FavouriteSongList; } MediaPlayList.FavouriteSongList.MoveTo((uint)i); if (MediaControl.MediaPlayer.PlaybackSession.PlaybackState != MediaPlaybackState.Playing) { MediaControl.MediaPlayer.Play(); } break; } } }; VoiceRec.NextSongCommanded += (s, m) => { MediaPlayList.FavouriteSongList.MoveNext(); if (MediaControl.MediaPlayer.PlaybackSession.PlaybackState != MediaPlaybackState.Playing) { MediaControl.MediaPlayer.Play(); } }; VoiceRec.PreviousSongCommanded += (s, m) => { MediaPlayList.FavouriteSongList.MovePrevious(); if (MediaControl.MediaPlayer.PlaybackSession.PlaybackState != MediaPlaybackState.Playing) { MediaControl.MediaPlayer.Play(); } }; Loaded -= MusicPage_Loaded; }