protected void addCommonActions() { var l = new List <CharmAction> { new CharmAction("取消选择", "\xE10E", this.btn_cancel_selection_Click, isMultiSelect), new CharmAction("播放/暂停", "\xE102", this.btn_play_Click, (s) => { string id = null; var song = SelectedSongs.FirstOrDefault(); if (song != null) { id = song.Id; } this.actions["播放/暂停"].Icon = Mp3Player.GetPlayOrPause(id) ? "\xE102":"\xE103"; return(true); }), new CharmAction("选中正在播放", "\xE18B", this.btn_select_nowplaying_Click, (s) => false), new CharmAction("下一首", "\xE101", this.btn_next_Click, (s) => false), new CharmAction("收藏", "\xE0A5", this.btn_fav_Click, canFav), new CharmAction("不再收藏", "\xE007", this.btn_unfav_Click, canUnfav), new CharmAction("查看专辑", "\xE1d2", link_album, IsOnlyType <IHasAlbum>), new CharmAction("查看艺术家", "\xe13d", link_artist, IsOnlyType <IHasArtist>), new CharmAction("查看精选集的歌曲", "\xE189", link_collection, IsOnlyType <CollectViewModel>), new CharmAction("查看艺术家的最受欢迎歌曲", "\xE189", link_artist, IsOnlyType <ArtistViewModel>), new CharmAction("查看艺术家的专辑", "\xE1d2", link_artist_album, IsOnlyType <ArtistViewModel>), new CharmAction("查看艺术家的相似艺人", "\xE125", link_similar_artist, IsOnlyType <ArtistViewModel>), new CharmAction("在浏览器中打开", "\xE12B", this.btn_browse_Click, IsOnlyType <MusicViewModel>), }; foreach (var item in l) { actions[item.Label] = item; } }
protected virtual void btn_play_Click(object sender, RoutedEventArgs e) { var item = SelectedSongs.FirstOrDefault() ?? Items.OfType <SongViewModel>().FirstOrDefault(); if (item == null) { return; } var location = item.Song.DownloadState == "complete" ? item.Song.FilePath : item.Song.UrlMp3; if (string.IsNullOrEmpty(location)) { return; } if (Mp3Player.GetPlayOrPause(item.Id)) { if (!PlayList.Contains(item)) { PlayList.NeedsRefresh(); PlayList.Refresh(Items.OfType <SongViewModel>()); } else if (isMultiSelect(this)) { PlayList.NeedsRefresh(); PlayList.Refresh(SelectedSongs); } } Mp3Player.Play(location, item.Id); ActionBarService.Refresh(); }