/// <summary> /// 在当前播放列表加入 /// </summary> /// <param name="music"></param> public static void Add(IMusic music, bool play = true) { Musics.Add(music); if (play) { index = Musics.Count - 1; } }
public void AddMusic(Model.Music music) { XML.MediaXML mediaXML = new XML.MediaXML(); mediaXML.Load("musics.xml"); if (!mediaXML.HasMedia(music.Path)) { mediaXML.Add(music.Path, music.Stream); mediaXML.WriteInFile("musics.xml"); if (music.Name.Contains(this._SearchInput)) { Musics.Add(music); } MusicsTmp.Add(music); } }
/// <summary> /// Add music to Collection. /// </summary> /// <param name="path">Path of music file</param> private void AddMusic(string path) { Music music; try { var tag = new Mp3File(path).TagHandler; music = new Music(tag.Title, tag.Artist, tag.Album, BitmapToBitmapImage(new Bitmap(tag.Picture)), path); } catch (Exception e) { Console.WriteLine(e.Message); // No ID3 Tag music = new Music(path.Substring(path.LastIndexOf('\\') + 1), "None", "None", null, path); } if (!Musics.Contains(music)) { Musics.Add(music); MusicList.Items.Refresh(); SaveMusicList(); } }
/// <summary> /// Ask to the user to chose a folder and display content. Subfolders are also displayed. /// </summary> private void Browse() { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { FolderPath = fbd.SelectedPath; IEnumerable <MusicFileDao> files = new MusicFileDaoDetector().SearchInDirectory(FolderPath); // Load path files and metas for each Musics.Clear(); IEnumerable <MusicItem> musicFiles = files.Select(p => new MusicItem() { FileName = p.FileName, Path = p.Path, File = p }); foreach (MusicItem file in musicFiles) { Musics.Add(file); } } }
private void buildLocalMusicAlbumArtistModels() { foreach (var song in Service.Library.Musics) { var music = new LocalMusicModel { Music = song, Image = Service.Library.Thumbnails.Where(t => t.Id == song.ThumbnailId).FirstOrDefault().Image }; Musics.Add(music); var privilegedArtist = ""; if (song.AlbumArtist != UNKNOWN_ARTIST) { privilegedArtist = song.AlbumArtist; } else if (song.Artist != UNKNOWN_ARTIST) { privilegedArtist = song.Artist; } else { privilegedArtist = UNKNOWN_ARTIST; } var album = Albums.Where(a => a.Title == song.AlbumTitle && a.AlbumArtist == privilegedArtist).FirstOrDefault(); if (album == null) { album = new LocalAlbumModel { Title = song.AlbumTitle, AlbumArtist = privilegedArtist, Image = Service.Library.Thumbnails.Where(t => t.Id == music.Music.ThumbnailId).FirstOrDefault().Image, Year = song.Year }; album.Musics.Add(music); Albums.Add(album); } else { album.Musics.Add(music); } var artist = Artists.Where(a => a.Name == privilegedArtist).FirstOrDefault(); if (artist == null) { artist = new LocalArtistModel { Name = privilegedArtist }; artist.Albums.Add(album); artist.Musics.Add(music); Artists.Add(artist); } else { if (!artist.Albums.Contains(album)) { artist.Albums.Add(album); artist.Musics.Add(music); } else { artist.Musics.Add(music); } } } }