Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void bgwTimeManager_DoWork(object sender, DoWorkEventArgs e)
- {
- IsDefaultQueuePlaying = Operations.IsQueueEmpty();
- if (IsDefaultQueuePlaying)
- {
- var song = Operations.GetDefaultQueueSong();
- foreach (DataRow songRow in song.Rows)
- {
- SetAlbumText(songRow["artist"].ToString());
- SetPlaybackText(songRow["duration"].ToString());
- SetTitleText(songRow["title"].ToString());
- _path = songRow["path"].ToString();
- }
- if (song.Rows.Count > 0)
- {
- MethodInvoker mi = delegate { trackBar1.Enabled = true; };
- if (InvokeRequired)
- Invoke(mi);
- PlayMp3File(e);
- }
- else
- {
- SetAlbumText("Playlist empty...");
- SetPlaybackText("00:00");
- SetTitleText("Playlist empty...");
- MethodInvoker mi = delegate { trackBar1.Enabled = false; };
- if (InvokeRequired)
- Invoke(mi);
- }
- }
- else
- {
- DataTable queueTopSong = Operations.GetQueueTopSong();
- if (queueTopSong.Rows.Count > 0)
- {
- var song = Operations.GetQueueSong(queueTopSong.Rows[0]["s_id"].ToString());
- foreach (DataRow songRow in song.Rows)
- {
- SetAlbumText(songRow["artist"].ToString());
- SetPlaybackText(songRow["duration"].ToString());
- SetTitleText(songRow["title"].ToString());
- _path = songRow["path"].ToString();
- }
- if (song.Rows.Count > 0)
- {
- MethodInvoker mi = delegate { trackBar1.Enabled = true; };
- if (InvokeRequired)
- Invoke(mi);
- ReadDedication(queueTopSong);
- PlayMp3File(e);
- Operations.DeleteRowFromQueue(queueTopSong.Rows[0]["q_id"].ToString());
- }
- else
- {
- SetAlbumText("Playlist empty...");
- SetPlaybackText("00:00");
- SetTitleText("Playlist empty...");
- MethodInvoker mi = delegate { trackBar1.Enabled = false; };
- if (InvokeRequired)
- Invoke(mi);
- }
- }
- }
- }
- private void ReadDedication(DataTable queueTopSong)
- {
- _readDedication = new SpeechSynthesizer();
- _readDedication.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
- _readDedication.Rate = 1;
- DataTable dedication = Operations.GetDedication(queueTopSong.Rows[0]["q_id"].ToString());
- for (var index = 0; index < dedication.Rows.Count; index++)
- {
- var msg = index == 0 ? "The Upcoming song is " : "This song is also ";
- DataRow dedicationRow = dedication.Rows[index];
- msg += $"dedicated to {dedicationRow["dedicatedto"]}";
- _readDedication.Speak(msg);
- Thread.Sleep(10);
- msg = $"By {dedicationRow["dedicatedby"]}";
- _readDedication.Speak(msg);
- Thread.Sleep(10);
- msg = $"Here is the dedication message of {dedicationRow["dedicatedby"]}";
- _readDedication.Speak(msg);
- Thread.Sleep(10);
- _readDedication.Speak(dedicationRow["dedicationmessage"].ToString());
- Thread.Sleep(10);
- Operations.DeleteDedication(dedicationRow["d_id"].ToString());
- }
- }
- private void PlayMp3File(DoWorkEventArgs e)
- {
- try
- {
- _reader = new AudioFileReader(_path);
- waveOut = new WaveOut();
- var meter = new MeteringSampleProvider(_reader);
- meter.StreamVolume += Meter_StreamVolume;
- var vol = 60;
- MethodInvoker mi = delegate { vol = trackBar1.Value; };
- if (InvokeRequired)
- Invoke(mi);
- waveOut.Volume = (float)vol / 100;
- waveOut.Init(_reader);
- waveOut.PlaybackStopped += WaveOutOnPlaybackStopped;
- waveOut.Play();
- //int secs = int.Parse(lblPlaybackTime.Text.Split(':')[1].Trim());
- //int mins = int.Parse(lblPlaybackTime.Text.Split(':')[0].Trim());
- while (_reader.CurrentTime != _reader.TotalTime)
- {
- SetPlaybackText(_reader.CurrentTime.ToString("hh':'mm':'ss"));
- //secs -= 1;
- if (bgwTimeManager.CancellationPending)
- {
- e.Cancel = true;
- waveOut.Stop();
- return;
- }
- Thread.Sleep(1000);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
Add Comment
Please, Sign In to add comment