Example #1
0
        private void audioList1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                Thread thread = new Thread(new ParameterizedThreadStart(this.ImportFiles));
                thread.Start(e.Data.GetData(DataFormats.FileDrop));
                this.reordering = false;
            }
            else if (this.reordering)
            {
                this.reordering = false;
                Point        point = this.audioList1.PointToClient(new Point(e.X, e.Y));
                ListViewItem item  = this.audioList1.GetItemAt(point.X, point.Y);

                if (this.audioList1.SelectedIndices.Count > 0 && item != null)
                {
                    int dest_index    = item.Index;
                    int current_index = this.audioList1.SelectedIndices[0];

                    if (dest_index != current_index)
                    {
                        AudioPlayerItem a = this.play_list[current_index];
                        this.audioList1.Items.RemoveAt(current_index);
                        this.play_list.RemoveAt(current_index);
                        this.play_list.Insert(dest_index, a);
                        this.audioList1.Items.Insert(dest_index, a);
                        this.SavePlaylist();
                    }
                }
            }
        }
Example #2
0
        private void ImportFiles(object arg)
        {
            List <String> files = new List <String>((String[])arg);

            files.Sort((x, y) => x.CompareTo(y));

            foreach (String f in files)
            {
                if (this.play_list.Find(x => x.Path == f) == null)
                {
                    AudioPlayerItem item = AudioHelpers.CreateAudioPlayerItem(this.Player, f);

                    if (item != null)
                    {
                        if (item.Duration > 0)
                        {
                            this.play_list.Add(item);
                            this.AddPlaylistItem(item);
                        }
                    }
                }
            }

            this.SavePlaylist();
        }
Example #3
0
 private void AddPlaylistItem(AudioPlayerItem item)
 {
     if (this.audioList1.InvokeRequired)
     {
         this.audioList1.BeginInvoke((Action)(() => this.AddPlaylistItem(item)));
     }
     else
     {
         this.audioList1.Items.Add(item);
     }
 }
Example #4
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();
        }
Example #5
0
        public void UpdateArt(AudioPlayerItem item)
        {
            this.artist = item.Artist.Trim();
            this.album  = item.Album.Trim();
            this.song   = item.Title.Trim();
            String[] arr = new String[] { artist, album, song };

            if (this.busy)
            {
                this.pending = true;
                return;
            }

            if (!String.IsNullOrEmpty(this.artist) && (!String.IsNullOrEmpty(this.album) || !String.IsNullOrEmpty(this.song)))
            {
                this.thread = new Thread(new ParameterizedThreadStart(this.Worker));
                this.thread.Start(arr);
            }
        }
Example #6
0
        private void removeFromPlaylistToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.audioList1.SelectedIndices.Count > 0)
            {
                int r = this.audioList1.SelectedIndices[0];

                if (r >= 0 && r < this.play_list.Count)
                {
                    AudioPlayerItem item = this.play_list[r];
                    this.audioList1.Items.RemoveAt(r);
                    this.play_list.RemoveAt(r);

                    if (item.Playing)
                    {
                        this.StopClicked();
                    }

                    this.SavePlaylist();
                }
            }
        }
Example #7
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);
        }
Example #8
0
 private void PlaySong(AudioPlayerItem item)
 {
     this.Player.URL = item.Path;
 }