string SavePlaylist(string path = null) { if (!SelectedSongs.Any()) { return(null); } Playlist.Clear(); foreach (var item in SelectedSongs) { Playlist.Add(string.Format("#EXTINF:{0}", item.Id)); if (string.IsNullOrEmpty(item.Song.FilePath)) { Playlist.Add(System.IO.Path.Combine(".", item.Dir, item.FileNameBase + ".mp3")); } else { Playlist.Add(item.Song.FilePath); } } if (path == null) { path = Global.AppSettings["DownloadFolder"] + "\\default.m3u"; } File.WriteAllLines(path, Playlist, Encoding.UTF8); return(path); }
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(); }
private void BindNumericBox(NumericUpDown box, PropertyInfo prop) { int values = (from e in SelectedSongs select prop.GetValue(e, null) as int?).Distinct().Count(); box.ForeColor = values == 1 ? SystemColors.ControlText : SystemColors.GrayText; box.Value = values == 1 ? (prop.GetValue(SelectedSongs.First(), null) as int?) ?? 0 : 0; }
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; } }
public void UpdateSelectedSongTitle() { SongList.SelectedIndexChanged -= SongList_SelectedIndexChanged; SongList.BeginUpdate(); List <int> selected = SongList.SelectedIndices.Cast <int>().ToList(); List <SongEntry> songs = SelectedSongs.ToList(); if (selected.Count != songs.Count) { return; } SongList.ClearSelected(); for (int i = 0; i < songs.Count; ++i) { SongList.Items[selected[i]] = songs[i]; } foreach (int i in selected) { SongList.SetSelected(i, true); } SongList.EndUpdate(); SongList.SelectedIndexChanged += SongList_SelectedIndexChanged; }
void BindNumericBox(NSTextField box, PropertyInfo prop) { int values = (from e in SelectedSongs select prop.GetValue(e, null) as int?).Distinct().Count(); box.TextColor = values == 1 ? NSColor.ControlText : NSColor.DisabledControlText; box.IntValue = values == 1 ? (prop.GetValue(SelectedSongs.First()) as int?) ?? 0 : 0; }
void BindBox(NSTextView box, PropertyInfo prop) { int values = (from e in SelectedSongs select prop.GetValue(e, null) as string).Distinct().Count(); box.TextColor = values == 1 ? NSColor.ControlText : NSColor.DisabledControlText; box.Value = values == 1 ? prop.GetValue(SelectedSongs.First()) as string ?? "" : "(Various)"; }
void btn_remove_complete_Click(object sender, RoutedEventArgs e) { var list = SelectedSongs.ToArray(); Task.Run(() => { SongViewModel.CanSave = false; foreach (var item in list) { try { File.Delete(item.Song.FilePath); File.Delete(Path.Combine(Global.BasePath, "cache", item.Id + ".mp3")); } catch { } Remove(item); SongViewModel.Remove(item.Id); } try { PersistHelper.Delete(list.Select(x => x.Song).ToArray()); } catch (Exception ex) { Jean_Doe.Common.Logger.Error(ex); } SongViewModel.CanSave = true; }); }
private void BindBox(TextBox box, PropertyInfo prop) { int values = (from e in SelectedSongs select prop.GetValue(e, null) as string).Distinct().Count(); box.ForeColor = values == 1 ? SystemColors.ControlText : SystemColors.GrayText; box.Text = values == 1 ? prop.GetValue(SelectedSongs.First(), null) as string : "(Various)"; }
protected virtual void btn_open_click(object sender, RoutedEventArgs e) { var s = SelectedSongs.FirstOrDefault(); if (s == null || !s.CanOpen) { return; } s.Open(); }
void btn_remove_Click(object sender, RoutedEventArgs e) { DownloadManager.Instance.RemoveByTag(SelectedSongs.Select(x => x.Id).ToArray()); var list = SelectedSongs.ToList(); foreach (var item in list) { Remove(item); } }
void btn_download_add_Click(object sender, RoutedEventArgs e) { var list = SelectedSongs.ToList(); var list_download = Artwork.DataBus.DataBus.Get("list_download") as DownloadSongListControl; foreach (var item in list) { list_download.AddAndStart(item); Remove(item); } }
protected override void item_double_click(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (SelectedSongs.Any()) { btn_play_Click(sender, e); } else { base.item_double_click(sender, e); } }
bool filter_select(object sender) { var music = sender as MusicViewModel; if (music == null) { return(false); } ; return(SelectedSongs.Contains(music)); }
void btn_complete_Click(object sender, RoutedEventArgs e) { if (!SelectedSongs.Any()) { return; } DownloadManager.Instance.StopByTag(SelectedSongs.Select(x => x.Id).ToArray()); foreach (var item in SelectedSongs) { item.HasMp3 = true; item.HasLrc = true; item.HasArt = true; MessageBus.Instance.Publish(new MsgDownloadStateChanged { Id = item.Id, Item = item, }); } }
void btn_save_playlist_Click(object sender, RoutedEventArgs e) { if (!SelectedSongs.Any()) { return; } var win = new System.Windows.Forms.SaveFileDialog { InitialDirectory = Global.AppSettings["DownloadFolder"], Filter = "播放列表文件 (*.m3u)|*.m3u", OverwritePrompt = true, Title = "存为播放列表" }; if (win.ShowDialog() == System.Windows.Forms.DialogResult.OK) { SavePlaylist(win.FileName); } }
void btn_cancel_Click(object sender, RoutedEventArgs e) { DownloadManager.Instance.StopByTag(SelectedSongs.Select(x => x.Id).ToArray()); }
private void DeleteFromPlaylist(SongViewModel songViewModel) { SelectedSongs.Remove(songViewModel); }
private void AddToPlaylist(SongViewModel songViewModel) { SelectedSongs.Add(songViewModel); }
private void SelectSong(SongViewModel songViewModel) { SelectedSongs.Add(songViewModel); }
private void UnselectSong(SongViewModel songViewModel) { SelectedSongs.Remove(songViewModel); }