/// <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); }
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; }
private async void Song_Click(object sender, RoutedEventArgs e) { var id = Convert.ToInt32((sender as FrameworkElement).Tag); var song = await Task.Factory.StartNew(() => { return(_musicService.GetMusicById(id)); }); var model = new MusicModel() { Id = song.Id, SingerId = song.SingerId, AlbumId = song.AlbumId, Name = song.Name, SingerName = song.SingerName, AlbumName = song.AlbumName, FileUri = new Uri(song.FileUrl, UriKind.Relative), Duration = song.Duration }; JMApp.CurrentPlayingMusicsInfo = new CurrentPlayingMusicsInfo() { PlayingListMusics = new List <MusicModel>() { model }, IsCurrentPlayingPage = true, }; if (JMApp.CurrentPlayingMusicsInfo.CurrentPlayingMusic?.Id.Equals(id) != true) { JMApp.CurrentPlayingMusicsInfo.CurrentPlayingMusic = model; } var isToPlay = _currentPlayingMusicId != model.Id; await Task.Factory.StartNew(() => MusicPlayStateChangedUtil.InvokeFromJM(model, isToPlay)); _currentPlayingMusicId = isToPlay ? model.Id : 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); } }