示例#1
0
 private void playSelectedFile()
 {
     if (this.selectedSong == null)
     {
         return;
     }
     if (waveOut.PlaybackState == PlaybackState.Playing)
     {
         waveOut.Stop();
         this.timer.Stop();
     }
     waveOut.Dispose();
     waveOut          = null;
     this.playingSong = selectedSong;
     this.reader      = new Mp3FileReader(this.selectedSong.filePath);
     waveOut          = new WaveOut(); // or WaveOutEvent()
     waveOut.Init(this.reader);
     filenameLabel.Text              = this.playingSong.fileName;
     durationField.Text              = String.Format("{0:00}:{1:00}", playingSong.fileDuration.Minutes, playingSong.fileDuration.Seconds);
     this.songTrackBar.Minimum       = 0;
     this.songTrackBar.Maximum       = Convert.ToInt32(Math.Round(this.selectedSong.fileDuration.TotalSeconds));
     this.songTrackBar.TickFrequency = 1;
     this.songTrackBar.Value         = 0;
     this.timer.Interval             = 1000;
     waveOut.Play();
     this.songProgress = 0;
     this.timer.Start();
     playButton.BackColor = Color.Black;
 }
示例#2
0
 private void songTrackBar_Scroll(object sender, EventArgs e)
 {
     if (playingSong != null)
     {
         if (songTrackBar.Value < songTrackBar.Maximum)
         {
             this.waveOut.Pause();
             Seeking(songTrackBar.Value);
         }
         else if (songTrackBar.Value == songTrackBar.Maximum)
         {
             scrollingMax = true;
             int indexOf = playList.IndexOf(playingSong);
             if (indexOf < playList.Count - 1)
             {
                 this.waveOut.Stop();
                 this.timer.Stop();
                 this.selectedSong     = playList.ElementAt(indexOf + 1);
                 listBox1.SelectedItem = this.selectedSong;
                 listBox1.Focus();
                 listBox1.Update();
                 this.playSelectedFile();
             }
             else
             {
                 this.waveOut.Stop();
                 this.timer.Stop();
                 this.songTrackBar.Value = 0;
             }
         }
     }
 }
示例#3
0
 private void openToolStripButton_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
     {
         string        file   = openFileDialog1.FileName;
         string        name   = Path.GetFileNameWithoutExtension(file);
         Mp3FileReader reader = new Mp3FileReader(file);
         playList.Add(new AudioFileInfo {
             filePath = file, fileName = name, fileDuration = reader.TotalTime
         });
         updateListBox();
         if (first)
         {
             this.selectedSong     = playList.ElementAt(0);
             listBox1.SelectedItem = this.selectedSong;
             listBox1.Focus();
             listBox1.Update();
             first = false;
             this.playSelectedFile();
         }
         else
         {
             listBox1.SelectedItem = this.selectedSong;
             listBox1.Focus();
             listBox1.Update();
         }
     }
 }
示例#4
0
 private void Form1_DragEnter(object sender, DragEventArgs e)
 {
     string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
     if (files != null)
     {
         foreach (string file in files)
         {
             if (playList.Any(x => x.filePath == file))
             {
                 continue;
             }
             else
             {
                 string        name   = Path.GetFileNameWithoutExtension(file);
                 Mp3FileReader reader = new Mp3FileReader(file);
                 playList.Add(new AudioFileInfo {
                     filePath = file, fileName = name, fileDuration = reader.TotalTime
                 });
                 updateListBox();
             }
         }
         if (first)
         {
             this.selectedSong     = playList.ElementAt(0);
             listBox1.SelectedItem = this.selectedSong;
             listBox1.Focus();
             listBox1.Update();
             first = false;
             this.playSelectedFile();
         }
     }
 }
示例#5
0
 private void selectedMusicChanged(object sender, EventArgs e)
 {
     if (!isDragDrop)
     {
         AudioFileInfo mp3File = (AudioFileInfo)this.listBox1.SelectedItem;
         this.selectedSong = mp3File;
     }
 }
示例#6
0
 private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (this.waveOut.PlaybackState == PlaybackState.Paused && selectedSong == playingSong)
     {
         this.waveOut.Play();
         this.timer.Start();
     }
     else
     {
         this.selectedSong = (AudioFileInfo)listBox1.SelectedItem;
         this.playSelectedFile();
     }
     Invalidate(true);
 }
示例#7
0
 private void nextButton_Click(object sender, EventArgs e)
 {
     if (playingSong != null)
     {
         int indexOf = playList.IndexOf(playingSong);
         if (indexOf < playList.Count - 1)
         {
             this.waveOut.Stop();
             this.timer.Stop();
             this.selectedSong     = playList.ElementAt(indexOf + 1);
             listBox1.SelectedItem = this.selectedSong;
             listBox1.Focus();
             listBox1.Update();
             this.playSelectedFile();
         }
     }
 }
示例#8
0
 private void listBox1_DragDrop(object sender, DragEventArgs e)
 {
     if (!e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         Point point = listBox1.PointToClient(new Point(e.X, e.Y));
         int   index = this.listBox1.IndexFromPoint(point);
         if (index < 0)
         {
             index = this.listBox1.Items.Count - 1;
         }
         AudioFileInfo data = (AudioFileInfo)listBox1.SelectedItem;
         this.listBox1.Items.Remove(data);
         this.playList.Remove(data);
         this.playList.Insert(index, data);
         this.listBox1.Items.Insert(index, data);
         listBox1.SelectedItem = this.selectedSong;
         listBox1.Focus();
         listBox1.Update();
         isDragDrop = false;
     }
 }
示例#9
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            AudioFileInfo deleteObject = (AudioFileInfo)this.listBox1.SelectedItem;

            if (playingSong == deleteObject)
            {
                return;
            }
            listBox1.Items.Remove(deleteObject);
            playList.Remove(deleteObject);
            if (playedList.Count > 0)
            {
                playedList.Remove(deleteObject);
            }
            listBox1.SelectedItem = this.selectedSong;
            listBox1.Focus();
            listBox1.Update();
        }
示例#10
0
 private void songTrackBar_ValueChanged(object sender, EventArgs e)
 {
     if (songTrackBar.Value == songTrackBar.Maximum)
     {
         if (shuffle)
         {
             playedList.Add(playingSong);
             if (playList.Count == playedList.Count)
             {
                 this.waveOut.Stop();
                 this.timer.Stop();
             }
             else
             {
                 int index = random.Next(0, playList.Count);
                 while (playedList.Contains(playList.ElementAt(index)))
                 {
                     index = random.Next(0, playList.Count);
                 }
                 this.selectedSong     = playList.ElementAt(index);
                 listBox1.SelectedItem = this.selectedSong;
                 listBox1.Focus();
                 listBox1.Update();
                 this.waveOut.Stop();
                 this.timer.Stop();
                 playSelectedFile();
             }
         }
         else
         {
             if (!scrollingMax)
             {
                 int indexOf = playList.IndexOf(playingSong);
                 if (indexOf == playList.Count - 1)
                 {
                     if (repeat == 1)
                     {
                         this.waveOut.Stop();
                         this.timer.Stop();
                         this.selectedSong     = playList.ElementAt(0);
                         listBox1.SelectedItem = this.selectedSong;
                         listBox1.Focus();
                         listBox1.Update();
                         this.playSelectedFile();
                     }
                     else if (repeat == 2)
                     {
                         this.waveOut.Stop();
                         this.timer.Stop();
                         this.Loop();
                     }
                     else
                     {
                         this.waveOut.Stop();
                         this.timer.Stop();
                     }
                 }
                 else if (repeat == 2)
                 {
                     this.waveOut.Stop();
                     this.timer.Stop();
                     this.Loop();
                 }
                 else if (indexOf < playList.Count)
                 {
                     this.waveOut.Stop();
                     this.timer.Stop();
                     this.selectedSong     = playList.ElementAt(indexOf + 1);
                     listBox1.SelectedItem = this.selectedSong;
                     listBox1.Focus();
                     listBox1.Update();
                     this.playSelectedFile();
                 }
             }
         }
     }
     scrollingMax = false;
 }