예제 #1
0
파일: Form1.cs 프로젝트: Magicpig55/MMP
        private void LoadSong(string url, bool fromPlaylist = false)
        {
            string ext = Path.GetExtension(url);
            if (loaded) {
                wave.Dispose();
                wvcn.Dispose();
                strm.Dispose();
            }
            if (ext.IndexOf("wav") >= 0) {
                strm = new WaveFileReader(url);
            } else if (ext.IndexOf("mp3") >= 0) {
                strm = new Mp3FileReader(url);
            } else {
                return;
            }
            if (!fromPlaylist && playlistActive) {
                DialogResult res = MessageBox.Show("Add this song to the current Playlist?", "Update Playlist", MessageBoxButtons.YesNo);
                if (res == DialogResult.Yes) {
                    currentPlaylist.AddSong(url);
                    DialogResult mes = MessageBox.Show("Save Playlist?", "Save Playlist", MessageBoxButtons.YesNo);
                    if (res == DialogResult.Yes) {
                        currentPlaylist.Save();
                    }
                } else {
                    playlistActive = false;
                }
            }
            wave = new WaveOut();
            wvcn = new WaveChannel32(strm);
            wvcn.PadWithZeroes = false;
            wvcn.Sample += new EventHandler<SampleEventArgs>(SampleEvent);
            wave.PlaybackStopped += (pbss, e) => {
                playing = false;
                nextpos = 0;
                LoadNext();
            };
            wave.Volume = volume;
            wave.Init(wvcn);
            loaded = true;
            playing = true;
            currentSong = new Song(url, true);
            if (currentSong.HasArt) {
                SongColor = ImageProcessor.AverageColor(new Bitmap(currentSong.art));
                colorMode = ColorMode.Image;
            } else {
                colorMode = ColorMode.Random;
            }
            wave.Play();

            using (Graphics g = Graphics.FromImage(SongInformation)) {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                StringFormat centered = new StringFormat();
                centered.Alignment = StringAlignment.Center;
                centered.LineAlignment = StringAlignment.Center;
                RectangleF borp = new RectangleF(0, 10, SongInformation.Width, SongInformation.Height);
                borp.Inflate(-5, -10);
                g.FillRectangle(Brushes.Lime, borp);
                int amt = 1 + (currentSong.album != null ? 1 : 0) + (currentSong.albumArtists != "" ? 1 : 0);
                borp.Height /= amt;
                g.DrawString(currentSong.title, SongInfoTitleFont, Brushes.Black, borp, centered);
                borp.Y += borp.Height;
                if (currentSong.album != null) {
                    g.DrawString(currentSong.album, SongInfoSubFont, Brushes.Black, borp, centered);
                    borp.Y += borp.Height + 5;
                }
                if (currentSong.albumArtists != "") {
                    g.DrawString(currentSong.albumArtists, SongInfoSubFont, Brushes.Black, borp, centered);
                    borp.Y += borp.Height + 5;
                }
            }
        }
예제 #2
0
파일: Playlist.cs 프로젝트: Magicpig55/MMP
 public void AddSong(String url)
 {
     Song song = new Song(url);
     Songs.Add(song);
 }