Beispiel #1
0
        public static void Index(string[] paths)
        {
            Parallel.ForEach<string>(GetFiles(paths), filename =>
            {
                TagLib.File file = TagLib.File.Create(filename);
                var song = new Song
                {
                    Title = file.Tag.Title.ToASCII() ?? "Unknown",
                    Location = filename,
                    Artist = file.Tag.FirstAlbumArtist.ToASCII() ?? file.Tag.FirstPerformer.ToASCII() ?? "Unknown",
                    Album = file.Tag.Album.ToASCII() ?? "Unknown",
                    Genre = file.Tag.FirstGenre.ToASCII() ?? "Unknown",
                    Id = Guid.NewGuid().ToString(),
                };

                Songs.Add(song);
            });

            // index child directories
            Parallel.ForEach<string>(paths, path =>
            {
                try
                {
                    Index(Directory.GetDirectories(path));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            });
        }
Beispiel #2
0
 public static int Push(Song song)
 {
     queue.Enqueue(song);
     if (wmp.playState == WMPPlayState.wmppsStopped || wmp.playState == WMPPlayState.wmppsUndefined)
     {
         Next();
     }
     else
     {
         Console.WriteLine("Queued {0}", song.ToString());
     }
     return queue.Count;
 }
Beispiel #3
0
        private static void Play(Song song)
        {
            // update the song info
            song.PlayCount += 1;
            song.LastPlayed = DateTime.Now;

            // stop the media player
            wmp.controls.stop();
            wmp.PlayStateChange -= new _WMPOCXEvents_PlayStateChangeEventHandler(wmp_PlayStateChange);
            wmp.close();

            // create a new media player for the next song
            wmp = new WindowsMediaPlayer();
            wmp.PlayStateChange += new _WMPOCXEvents_PlayStateChangeEventHandler(wmp_PlayStateChange);
            wmp.URL = song.Location;
            wmp.controls.play();

            Console.WriteLine("Playing {0}", song.ToString());
        }