示例#1
0
        private ImageSource GetAlbumCover(Song song)
        {
            BitmapImage image= null;
            TagLib.File tlFile = TagLib.File.Create(song.FilePath);
            if (tlFile.Tag.Pictures.Count() > 0)
            {
                MemoryStream ms = new MemoryStream(tlFile.Tag.Pictures[0].Data.Data);
                ms.Seek(0, SeekOrigin.Begin);

                // ImageSource for System.Windows.Controls.Image
                image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = ms;
                image.EndInit();
            }
            return image;
        }
示例#2
0
        public LyricsManager(Song song)
        {
            SongInfoModel songinfo = new SongInfoModel() { Lyrics = new List<LyricsLine>() };
            songinfo.Title = "I'll be back";
            songinfo.Artists = "Beatles";
            songinfo.Lyrics.Add(new LyricsLine() { Line = " You know if you break my heart I'll go", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "But I'll be back again", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "Cos I told you once before goodbye", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "But I came back again", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "I love you so", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "I'm the one who wants you", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "Yes, I'm the one", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "Who wants you, oh ho, oh ho, oh", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "You could find better things to do", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "Than to break my heart again", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "This time I will try to show that I'm", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "Not trying to pretend", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "I thought that you would realize", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "That if I ran away from you", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "That you would want me too", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "But I got a big surprise", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "Oh ho, oh ho, oh", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "You could find better things to do", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "Than to break my heart again", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "This time I will try to show that I'm", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "Not trying to pretend", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "I wanna go but I hate to leave you,", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "You know I hate to leave you , oh ho, oh ho, oh", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "You, if you break my heart I'll go", Time = 2 });
            songinfo.Lyrics.Add(new LyricsLine() { Line = "But I'll be back again", Time = 2 });

            XmlSerializer xmlserializer = new XmlSerializer(typeof(SongInfoModel));
            string songpath = song.FilePath;
            string fileaddress = songpath.Remove(songpath.Length - 3, 3) + "xml";
            StreamWriter sw = new StreamWriter(fileaddress);
                xmlserializer.Serialize(sw,songinfo);
                sw.Close();
        }
示例#3
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            m_artistlist = new List<Artist>();
            m_albumslist = new List<Album>();
            m_songslist = new List<Song>();
            string[] files = null;
            for (int i = 0; i <= m_directories.Length; i++)
            {

                if (i == 0)
                    files = m_files;
                else
                    files = Directory.GetFiles(m_directories[i - 1]);

                foreach (string file in files)
                {
                    string x = System.IO.Path.GetExtension(file);
                    if (x == ".mp3")
                    {
                        TagLib.File tlFile;
                        try
                        {
                            tlFile = TagLib.File.Create(file);
                            Song song = new Song();
                            song.Title = tlFile.Tag.Title; // get song  title
                            song.FilePath = file; // get file path

                            //////////******** GET ARTIST *******///////
                            string artistname = tlFile.Tag.Performers[0]; // get artist name
                            Artist artist = GetArtist(artistname);
                            if (artist == null)
                            {
                                artist = new Artist() { Name = artistname };
                                m_artistlist.Add(artist);
                            }
                            song.Artist = artist;

                            //////////******** END OF GET ARTIST *******///////

                            //////////******** GET ALBUM *******///////
                            string albumname = tlFile.Tag.Performers[0]; // get album name
                            Album album = GetAlbum(albumname);
                            if (album == null)
                            {
                                album = new Album() { Name = albumname };
                                m_albumslist.Add(album);

                            }
                            song.Album = album;
                            album.Songs.Add(song);
                            if (!artist.Albums.Contains(album))
                                artist.Albums.Add(album);
                            //////////******** END OF GET ALBUM *******///////

                            m_songslist.Add(song);
                        }
                        catch (Exception ex) { }
                    }
                }
            }
            m_worker.ReportProgress(100);
        }