private SongViewModel LookupSong(SongModel song) { if (song == null) { return(null); } if (SongLookupMap.ContainsKey(song.SongId)) { return(SongLookupMap[song.SongId]); } else { ArtistViewModel artist = LookupArtistById(song.ArtistId); AlbumViewModel album = LookupAlbumById(song.AlbumId); SongViewModel newSongViewModel = new SongViewModel(song, artist, album); SongLookupMap.Add(newSongViewModel.SongId, newSongViewModel); SongCollection.Add(newSongViewModel, newSongViewModel.SortName); FlatSongCollection.Add(newSongViewModel); if (LibraryLoaded) { NotifyPropertyChanged(Properties.IsEmpty); } return(newSongViewModel); } }
/// <summary> /// Add the specified Song to the local collections and persistent storage /// </summary> /// <param name="songToAdd"></param> public static async void AddSongAsync(Song songToAdd) { // Must wait for this to get the song id await DbAccess.InsertAsync(songToAdd); lock ( lockObject ) { SongCollection.Add(songToAdd); IdLookup.Add(songToAdd.Id, songToAdd); artistAlbumLookup.AddValue(songToAdd.ArtistAlbumId, songToAdd); albumLookup.AddValue(songToAdd.AlbumId, songToAdd); } }
/// <summary> /// Loads Content /// </summary> /// <param name="Content"></param> public void LoadContent(ContentManager Content) { this.Content = Content; _currentScreen.LoadContent(); _image.LoadContent(); //_bgm = Content.Load<Song>("sfx/bgm"); //MediaPlayer.IsRepeating = true; //MediaPlayer.Play(_bgm); // Load And Play Music. try { SongCollection playlist = new SongCollection(); playlist.Add(Content.Load <Song>("sfx/Robert del Naja - the shovel")); playlist.Add(Content.Load <Song>("sfx/Robert del Naja - HS")); playlist.Add(Content.Load <Song>("sfx/Robert del Naja - WS")); playlist.Add(Content.Load <Song>("sfx/Robert del Naja - DT3")); playlist.Add(Content.Load <Song>("sfx/Robert del Naja - BC")); MediaPlayer.IsRepeating = true; MediaPlayer.Play(playlist); } catch (Exception e) { } }
public Gamestate(ContentManager content, bool transparent, string bgMusicFolder = null) { Transparent = transparent; _content = content; if (!String.IsNullOrEmpty(bgMusicFolder)) { BgMusic = new SongCollection(); string folder = "Content/" + c_bgMusicDir + bgMusicFolder + "/"; foreach (string filename in Directory.GetFiles(folder)) { string name = filename.Remove(0, "Content/".Length); BgMusic.Add(Content.Load<Song>(name)); } } if (BgMusic != null) { MediaPlayer.Play(BgMusic, s_rand.Next(BgMusic.Count)); } }
internal void AlertSongNameChanged(SongViewModel songViewModel, string oldName) { SongCollection.Remove(songViewModel, oldName); SongCollection.Add(songViewModel, songViewModel.SortName); }
public void Register(Song song) { songs.Add(song); }
private void loadSongs() { mySongs = new SongCollection(); mySongs.Add(new Song("Eric Clapton", "After Midnight", 338)); mySongs.Add(new Song("Sister Hazel", "All for You", 392)); mySongs.Add(new Song("Josh Groban", "America (Live Album Version)", 249)); mySongs.Add(new Song("The Surfaris", "Apache", 171)); mySongs.Add(new Song("Sister Hazel", "Beautiful Thing", 280)); mySongs.Add(new Song("Jesse McCartney", "Because You Live", 223)); mySongs.Add(new Song("The Ramones", "Blitzkreig Bop", 97)); mySongs.Add(new Song("Eric Clapton", "Blues Power", 440)); mySongs.Add(new Song("The Police", "Bring On the Night", 316)); mySongs.Add(new Song("Sister Hazel", "Champagne High", 306)); mySongs.Add(new Song("Sister Hazel", "Change Your Mind", 312)); mySongs.Add(new Song("Black Sabbath", "Children of the Grave", 326)); mySongs.Add(new Song("Black Sabbath", "Children of the Sea", 369)); mySongs.Add(new Song("Eric Clapton", "Cocaine", 459)); mySongs.Add(new Song("Zero 7", "Destiny", 224)); mySongs.Add(new Song("Eric Clapton", "Double Trouble", 492)); mySongs.Add(new Song("Neil Finn & Johnny Marr", "Down on the Corner", 271)); mySongs.Add(new Song("Dokken", "Dream Warriors", 254)); mySongs.Add(new Song("Eric Clapton", "Early In the Morning", 431)); mySongs.Add(new Song("Santana", "Esperando", 357)); mySongs.Add(new Song("Coldplay", "Fix You", 277)); mySongs.Add(new Song("Black Sabbath", "Fluff", 60)); mySongs.Add(new Song("Foghat", "Fool for the City", 331)); mySongs.Add(new Song("Eisley", "Golly Sandra (Live Version)", 218)); mySongs.Add(new Song("The Veronicas", "Heavily Broken (Live Version)", 259)); mySongs.Add(new Song("Zero 7", "Home", 383)); mySongs.Add(new Song("Neil Finn & Eddie Vedder", "I See Red", 211)); mySongs.Add(new Song("John Denver", "I Want to Live", 226)); mySongs.Add(new Song("Black Sabbath", "Iron Man", 450)); mySongs.Add(new Song("The Police", "King of Pain", 353)); mySongs.Add(new Song("Eric Clapton", "Lay Down Sally", 335)); mySongs.Add(new Song("Kenny Wayne Shepherd", "Live On", 275)); mySongs.Add(new Song("Michael W. Smith", "Live the Life", 275)); mySongs.Add(new Song("Big & Rich", "Live This Life (Music Only)", 262)); mySongs.Add(new Song("Kenny Chesney", "Live Those Songs", 248)); mySongs.Add(new Song("Belle and Sebastian", "Mayfly (Live Version)", 228)); mySongs.Add(new Song("The Police", "Message in a Bottle", 276)); mySongs.Add(new Song("Zero 7", "Morning Song", 426)); mySongs.Add(new Song("Dokken", "Mr. Scary", 503)); mySongs.Add(new Song("Madonna", "Music", 151)); mySongs.Add(new Song("Black Sabbath", "N.I.B.", 309)); mySongs.Add(new Song("Black Sabbath", "Neon Knights", 276)); mySongs.Add(new Song("Goldfrapp", "Number 1", 244)); mySongs.Add(new Song("Josh Groban", "Oceano (Live Album Version)", 232)); mySongs.Add(new Song("The Ramones", "Pet Sematary", 220)); mySongs.Add(new Song("The Surfaris", "Pipeline", 123)); mySongs.Add(new Song("Sarah McLachlan", "Push", 244)); }
static void Main(string[] args) { SongCollection mySongs = new SongCollection(); mySongs.Add(new Song("Eric Clapton", "After Midnight", 338)); mySongs.Add(new Song("Sister Hazel", "All for You", 392)); mySongs.Add(new Song("Josh Groban", "America (Live Album Version)", 249)); mySongs.Add(new Song("The Surfaris", "Apache", 171)); mySongs.Add(new Song("Sister Hazel", "Beautiful Thing", 280)); mySongs.Add(new Song("Jesse McCartney", "Because You Live", 223)); mySongs.Add(new Song("The Ramones", "Blitzkreig Bop", 97)); mySongs.Add(new Song("Eric Clapton", "Blues Power", 440)); mySongs.Add(new Song("The Police", "Bring On the Night", 316)); mySongs.Add(new Song("Sister Hazel", "Champagne High", 306)); mySongs.Add(new Song("Sister Hazel", "Change Your Mind", 312)); mySongs.Add(new Song("Black Sabbath", "Children of the Grave", 326)); mySongs.Add(new Song("Black Sabbath", "Children of the Sea", 369)); mySongs.Add(new Song("Eric Clapton", "Cocaine", 459)); mySongs.Add(new Song("Zero 7", "Destiny", 224)); mySongs.Add(new Song("Eric Clapton", "Double Trouble", 492)); mySongs.Add(new Song("Neil Finn & Johnny Marr", "Down on the Corner", 271)); mySongs.Add(new Song("Dokken", "Dream Warriors", 254)); mySongs.Add(new Song("Eric Clapton", "Early In the Morning", 431)); mySongs.Add(new Song("Santana", "Esperando", 357)); mySongs.Add(new Song("Coldplay", "Fix You", 277)); mySongs.Add(new Song("Black Sabbath", "Fluff", 60)); mySongs.Add(new Song("Foghat", "Fool for the City", 331)); mySongs.Add(new Song("Eisley", "Golly Sandra (Live Version)", 218)); mySongs.Add(new Song("The Veronicas", "Heavily Broken (Live Version)", 259)); mySongs.Add(new Song("Zero 7", "Home", 383)); mySongs.Add(new Song("Neil Finn & Eddie Vedder", "I See Red", 211)); mySongs.Add(new Song("John Denver", "I Want to Live", 226)); mySongs.Add(new Song("Black Sabbath", "Iron Man", 450)); mySongs.Add(new Song("The Police", "King of Pain", 353)); mySongs.Add(new Song("Eric Clapton", "Lay Down Sally", 335)); mySongs.Add(new Song("Kenny Wayne Shepherd", "Live On", 275)); mySongs.Add(new Song("Michael W. Smith", "Live the Life", 275)); mySongs.Add(new Song("Big & Rich", "Live This Life (Music Only)", 262)); mySongs.Add(new Song("Kenny Chesney", "Live Those Songs", 248)); mySongs.Add(new Song("Belle and Sebastian", "Mayfly (Live Version)", 228)); mySongs.Add(new Song("The Police", "Message in a Bottle", 276)); mySongs.Add(new Song("Zero 7", "Morning Song", 426)); mySongs.Add(new Song("Dokken", "Mr. Scary", 503)); mySongs.Add(new Song("Madonna", "Music", 151)); mySongs.Add(new Song("Black Sabbath", "N.I.B.", 309)); mySongs.Add(new Song("Black Sabbath", "Neon Knights", 276)); mySongs.Add(new Song("Goldfrapp", "Number 1", 244)); mySongs.Add(new Song("Josh Groban", "Oceano (Live Album Version)", 232)); mySongs.Add(new Song("The Ramones", "Pet Sematary", 220)); mySongs.Add(new Song("The Surfaris", "Pipeline", 123)); mySongs.Add(new Song("Sarah McLachlan", "Push", 244)); displaySongs(mySongs); mySongs[0].Play(); mySongs[0].Play(); mySongs[10].Play(); mySongs[0].Play(); mySongs[0].Play(); mySongs[12].Play(); mySongs[0].Play(); mySongs[5].Play(); mySongs[0].Play(); mySongs[19].Play(); Console.WriteLine("\n\n{0} songs in your collection have been played\n" , mySongs.PlayedCount); // SongCollection has total seconds. Use a TimeSpan structure to // easily convert to hours, minutes and seconds. One of its constructors // lets you specify the time span in hours, minutes and seconds. We have // the total time in seconds, so pass (0, 0, seconds) to the constructor. // Let it figure out how many hours, minutes and seconds that is by using // its Hours, Minutes and Seconds properties. // // Note this is different from the DateTime structure. TimeSpan ts = new TimeSpan(0, 0, mySongs.TotalLength); Console.WriteLine("Total playing time of your collection is {0}:{1}:{2}\n", ts.Hours, ts.Minutes, ts.Seconds); string artist; do { Console.Write("Please enter an artist (blank to stop): "); artist = Console.ReadLine(); if (artist != "") { SongCollection songsByOneArtist = mySongs.GetAllByArtist(artist); if (songsByOneArtist.Count > 0) { Console.WriteLine("\nSongs by {0} - Total Songs: {1}" , songsByOneArtist[0].Artist , songsByOneArtist.Count); Console.WriteLine(new string('=', 75)); displaySongs(songsByOneArtist); } else { Console.WriteLine("Nothing found by artist: {0}\n\n", artist); } } } while (artist != string.Empty); }
public MainViewModel() { if (IsInDesignMode) { // Code runs in Blend --> create design time data. Title = _title; NeteaseUrl = "http://music.163.com/#/my/m/music/playlist?id=6435531"; SongCollection.Add(new Song() { Title = new Title("Clover Heart's"), Artists = new Artists(new string[] { "榊原ゆい", "榊原ゆい" }), Album = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"), }); SongCollection.Add(new Song() { Title = new Title("Clover Heart's"), Artists = new Artists(new string[] { "榊原ゆい" }), Album = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"), }); SongCollection.Add(new Song() { Title = new Title("Clover Heart's"), Artists = new Artists(new string[] { "榊原ゆい" }), Album = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"), }); SelectedSong = SongCollection.First(); } else { // Code runs "for real" Title = _title; NeteaseUrl = "http://music.163.com/playlist?id=6435531"; Progress = 0; audioPlayback = new AudioPlayback(); audioPlayback.Volume = Volume; audioPlayback.EndCallback += (handle, channel, data, user) => { int index = -1; if ((index = SongCollection.IndexOf(CurrentPlaySong)) != -1) { ListenCommand.Execute(SongCollection.ElementAt((index + 1) % SongCollection.Count)); } else { audioPlayback.Stop(); NowPlaying = ""; CurrentPlaySong.PlayProgress = 0; CurrentPlaySong.PlayStatus = PlayStatus.Play; timer.Enabled = false; timer.Stop(); } }; timer.Tick += (sender, args) => { Title = string.Format("{0}/{1} - {2}", audioPlayback.CurrentLength, audioPlayback.TotalLength, _title); RaisePropertyChanged("Title"); CurrentPlaySong.PlayProgress = audioPlayback.Progress; }; GetSongsCommand = new RelayCommand(async() => { if (string.IsNullOrWhiteSpace(NeteaseUrl)) { return; } var id = ""; var urlType = ""; var reg = new Regex(@".*/(.*?)\?id=(\d*)").Match(NeteaseUrl); if (reg.Success) { urlType = reg.Groups[1].Value; id = reg.Groups[2].Value; SongCollection.Clear(); switch (urlType) { case "album": foreach (var song in await NeteaseUtil.GetSongsFromAlbum(id)) { SongCollection.Add(song); RaisePropertyChanged("TotalCount"); } break; case "artist": foreach (var song in await NeteaseUtil.GetSongsFromArtist(id)) { SongCollection.Add(song); RaisePropertyChanged("TotalCount"); } break; case "playlist": foreach (var song in await NeteaseUtil.GetSongsFromPlaylist(id)) { SongCollection.Add(song); RaisePropertyChanged("TotalCount"); } break; case "song": foreach (var song in await NeteaseUtil.GetSongDetail(id)) { SongCollection.Add(song); RaisePropertyChanged("TotalCount"); } break; } } else { SongCollection.Clear(); foreach (var song in await NeteaseUtil.SearchSongs(NeteaseUrl)) { SongCollection.Add(song); RaisePropertyChanged("TotalCount"); } } }); PlaylistDownloadCommand = new RelayCommand <Song>((song) => { SelectedSong = song; if (string.IsNullOrWhiteSpace(SongTrackUrl)) { return; } var downloader = new DownloadUtils(); downloader.DownloadProgressChanged += (sender, args) => { song.DownProgress = args.ProgressPercentage; BytesReceived = args.BytesReceived.ToString(); TotalBytesToReceive = args.TotalBytesToReceive.ToString(); }; downloader.DownloadFileCompleted += (sender, args) => { if (DownloadNext) { int index = -1; if ((index = SongCollection.IndexOf(song)) != -1 && index + 1 < SongCollection.Count) { PlaylistDownloadCommand.Execute(SongCollection.ElementAt(index + 1)); } } else { BytesReceived = "0"; TotalBytesToReceive = "0"; } }; downloader.Get(SongTrackUrl, Path.Combine("music", FileUtils.GetSafeFileName(song.SongFileName))); }); ListenCommand = new RelayCommand <Song>((song) => { SelectedSong = song; if (string.IsNullOrWhiteSpace(SongTrackUrl)) { return; } if (song.PlayStatus == PlayStatus.Play) { if (CurrentPlaySong != null && CurrentPlaySong != song) { audioPlayback.Stop(); CurrentPlaySong.PlayProgress = 0; CurrentPlaySong.PlayStatus = PlayStatus.Play; } audioPlayback.Load(SongTrackUrl); audioPlayback.Play(); CurrentPlaySong = song; NowPlaying = string.Format("Now Playing {0} - {1}", song.Artists, song.Title); timer.Enabled = true; timer.Start(); song.PlayProgress = 0; song.PlayStatus = PlayStatus.Stop; } else { audioPlayback.Stop(); NowPlaying = ""; song.PlayStatus = PlayStatus.Play; song.PlayProgress = 0; timer.Enabled = false; timer.Stop(); } }); OpenUrlCommand = new RelayCommand <string>((link) => { System.Diagnostics.Process.Start(link); }); CopyUrlCommand = new RelayCommand <string>((link) => { Clipboard.SetText(link); }); WindowClosing = new RelayCommand(() => { Properties.Settings.Default.Save(); }); } }