/// <summary> /// /// </summary> /// <param name="musicId"></param> /// <param name="type"></param> /// <param name="isToAdd">false 删除 true添加 null toggle</param> /// <returns></returns> public bool ToggleUserLike(int musicId, MusicRequestType type, bool?isToAdd = null) { if (_musicSourceType == MusicSourceType.JM) { var user = App.User; if (user != null) { switch (isToAdd) { case true: if (!MusicService.IsUserLike(user.Id, musicId, type)) { MusicService.ToggleUserLike(user.Id, musicId, type); } else { return(true); } break; case false: if (MusicService.IsUserLike(user.Id, musicId, type)) { MusicService.ToggleUserLike(user.Id, musicId, type); } else { return(true); } break; case null: MusicService.ToggleUserLike(user.Id, musicId, type); break; } if (_musicPlayerMenuViewModel.Id == musicId) { ChangeILikeState(); } return(true); } else { JMMessageBox.Show("添加我喜欢出错", "请先登录", JMMessageBoxButtonType.OK, JMMessageBoxIconType.Error); } } else { JMMessageBox.Show("添加我喜欢出错", "该音乐类型不支持", JMMessageBoxButtonType.OK, JMMessageBoxIconType.Error); } return(false); }
/// <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 async void BtnDownloadMusic_Click(object sender, RoutedEventArgs e) { if (_mediaPlayer.HasAudio && _musicSourceType == MusicSourceType.JM) { var uri = _musicPlayerMenuViewModel.FileUri; var musicName = _musicPlayerMenuViewModel.MusicName + System.IO.Path.GetExtension(uri.OriginalString); var singerName = _musicPlayerMenuViewModel.SingerName; await FileUtil.DownLoadMusicsAsync(uri, musicName, singerName); JMMessageBox.Show("歌曲下载", $"{musicName}下载成功", JMMessageBoxButtonType.OK, JMMessageBoxIconType.Success); } else { JMMessageBox.Show("下载音乐文件出错", "不支持下载", JMMessageBoxButtonType.OK, JMMessageBoxIconType.Error); } }
/// <summary> /// 我喜欢图标点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnILike_Click(object sender, RoutedEventArgs e) { try { if (_mediaPlayer.HasAudio) { ToggleUserLike(_musicPlayerMenuViewModel.Id, MusicRequestType.Song); } else { JMMessageBox.Show("添加我喜欢出错", "不存在播放音乐", JMMessageBoxButtonType.OK, JMMessageBoxIconType.Error); } } catch (Exception ex) { JMMessageBox.Show("添加我喜欢出错", ex.Message, JMMessageBoxButtonType.OK, JMMessageBoxIconType.Error); } }