コード例 #1
0
        /// <summary>
        /// 更改音乐播放状态
        /// </summary>
        /// <param name="musicViewModel"></param>
        /// <param name="tb"></param>
        private void ChangeMusicPlayState(QMInfoViewModel musicViewModel, TextBlock tb)
        {
            if (musicViewModel != null)
            {
                _nextPlayingTbObject = new KeyValuePair <string, TextBlock>(musicViewModel.Id, tb);
                var isToPlay = true;
                if (tb != null)
                {
                    isToPlay = !tb.Text.Equals("\ue69d");
                }

                Task.Factory.StartNew(() =>
                {
                    var htmlWeb = new HtmlWeb()
                    {
                        BrowserTimeout = TimeSpan.FromSeconds(10)
                    };
                    var doc      = htmlWeb.Load(musicViewModel.SourcePath);
                    var photoUrl = doc.DocumentNode.SelectNodes("//img[@class='data__photo']")?.FirstOrDefault()?.Attributes["src"].Value?.ToHttpUrl();

                    var musicInfo = new QMPlayInfoModel()
                    {
                        Id           = musicViewModel.Id,
                        Name         = musicViewModel.Name,
                        SingerName   = musicViewModel.SingerName,
                        TimeDuration = musicViewModel.TimeDuration,
                        Uri          = new Uri($"http://thirdparty.gtimg.com/C100{musicViewModel.Id}.m4a?fromtag=38", UriKind.Absolute),
                        PhotoUri     = photoUrl == null ? null : new Uri(photoUrl)
                    };

                    MusicPlayStateChangedUtil.InvokeFromQM(musicInfo, isToPlay);
                });
            }
        }
コード例 #2
0
 /// <summary>
 /// 歌曲播放失败
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MediaPlayer_MediaFailed(object sender, ExceptionEventArgs e)
 {
     _isOpenFailedOfCurrentPlayingMusic = true;
     //为了同步播放按钮的状态
     if (_musicSourceType == MusicSourceType.JM)
     {
         MusicPlayStateChangedUtil.InvokeFromJM(null, false, false);
     }
     else
     {
         MusicPlayStateChangedUtil.InvokeFromQM(null, false, false);
     }
     JMMessageBox.Show("歌曲失效", "因歌曲文件失效导致播放失败,请欣赏其他歌曲", JMMessageBoxButtonType.OK, JMMessageBoxIconType.Error);
 }
コード例 #3
0
 private void MediaPlayer_MediaOpened(object sender, EventArgs e)
 {
     if (_musicSourceType == MusicSourceType.JM)
     {
         MusicPlayStateChangedUtil.InvokeFromJM(null, true, false);
     }
     else
     {
         MusicPlayStateChangedUtil.InvokeFromQM(null, true, false);
     }
     MusicProgressSlider.Maximum        = _mediaPlayer.NaturalDuration.TimeSpan.TotalSeconds;
     SliderVolume.Maximum               = _mediaPlayer.Volume;
     _isOpenFailedOfCurrentPlayingMusic = false;
 }
コード例 #4
0
 /// <summary>
 /// 播放按钮点击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BtnPlay_Click(object sender, RoutedEventArgs e)
 {
     if (_musicSourceType.Equals(MusicSourceType.JM))
     {
         if (_mediaPlayer.Source == null)
         {
             PlayNewMusic(_defaultMusicUri);
             _musicPlayerMenuViewModel.MusicName  = "好想再爱你";
             _musicPlayerMenuViewModel.SingerName = "潘广益";
             _musicPlayerMenuViewModel.PhotoUri   = _defaultPhotoUri;
             _musicSourceType = MusicSourceType.JM;
         }
         else
         {
             MusicPlayStateChangedUtil.InvokeFromJM(null, !_isPlaying, false);
         }
     }
     else if (_musicSourceType == MusicSourceType.QM)
     {
         MusicPlayStateChangedUtil.InvokeFromQM(null, !_isPlaying, false);
     }
 }