Beispiel #1
0
        public void LoadPlaylist()
        {
            Thread thread = new Thread(new ThreadStart((Action)(() =>
            {
                try
                {
                    using (FileStream f = new FileStream(Settings.DataPath + "playlist.xml", FileMode.Open))
                    {
                        XmlReader xml = XmlReader.Create(new StreamReader(f));

                        xml.MoveToContent();
                        xml.ReadSubtree().ReadToFollowing("playlist");

                        while (xml.ReadToFollowing("item"))
                        {
                            AudioPlayerItem item = new AudioPlayerItem();
                            xml.ReadSubtree().ReadToFollowing("Album");
                            item.Album = Encoding.UTF8.GetString(Convert.FromBase64String(xml.ReadElementContentAsString()));
                            xml.ReadToFollowing("Artist");
                            item.Artist = Encoding.UTF8.GetString(Convert.FromBase64String(xml.ReadElementContentAsString()));
                            xml.ReadToFollowing("Author");
                            item.Author = Encoding.UTF8.GetString(Convert.FromBase64String(xml.ReadElementContentAsString()));
                            xml.ReadToFollowing("Length");
                            item.Duration = int.Parse(xml.ReadElementContentAsString());
                            item.SetDurationText(item.Duration);
                            xml.ReadToFollowing("Name");
                            item.Title = Encoding.UTF8.GetString(Convert.FromBase64String(xml.ReadElementContentAsString()));
                            xml.ReadToFollowing("Path");
                            item.Path = Encoding.UTF8.GetString(Convert.FromBase64String(xml.ReadElementContentAsString()));
                            this.play_list.Add(item);
                        }

                        xml.Close();
                    }
                }
                catch { }

                if (this.play_list.Count > 0)
                {
                    this.LockList(true);

                    foreach (AudioPlayerItem i in this.play_list)
                    {
                        this.AddPlaylistItem(i);
                    }

                    this.LockList(false);
                }
            })));

            thread.Start();
        }
Beispiel #2
0
        public static AudioPlayerItem CreateAudioPlayerItem(WindowsMediaPlayer wmp, String path)
        {
            AudioPlayerItem item = new AudioPlayerItem();

            try
            {
                IWMPMedia media = wmp.newMedia(path);

                if (media.duration > 0)
                {
                    item.Duration = (int)media.duration;
                    item.SetDurationText(item.Duration);
                    item.Title = media.name.Trim();
                    item.Path  = path;

                    for (int i = 0; i < media.attributeCount; i++)
                    {
                        switch (media.getAttributeName(i).ToUpper())
                        {
                        case "ALBUMIDALBUMARTIST":
                            String[] strs = media.getItemInfo(media.getAttributeName(i)).Split(new String[] { "*;*" }, StringSplitOptions.None);

                            if (strs.Length > 0)
                            {
                                item.Album = strs[0].Trim();
                            }
                            if (strs.Length > 1)
                            {
                                item.Artist = strs[1].Trim();
                            }
                            break;

                        case "AUTHOR":
                            item.Author = media.getItemInfo(media.getAttributeName(i)).Trim();
                            break;

                        case "DISPLAYARTIST":
                            if (item.Artist.Length == 0)
                            {
                                item.Artist = media.getItemInfo(media.getAttributeName(i)).Trim();
                            }
                            break;

                        case "TITLE":
                            if (item.Title.Length == 0)
                            {
                                item.Title = media.getItemInfo(media.getAttributeName(i)).Trim();
                            }
                            break;

                        case "WM/ALBUMARTIST":
                            if (item.Artist.Length == 0)
                            {
                                item.Artist = media.getItemInfo(media.getAttributeName(i)).Trim();
                            }
                            break;

                        case "WM/ALBUMTITLE":
                            if (item.Album.Length == 0)
                            {
                                item.Album = media.getItemInfo(media.getAttributeName(i)).Trim();
                            }
                            break;
                        }
                    }

                    if (String.IsNullOrEmpty(item.Artist))
                    {
                        item.Artist = item.Author;
                    }
                }
            }
            catch { return(null); }

            return(item);
        }