public SyncPoemAudio(DbBrowser dbBrowser, PoemAudio poemAudio) { InitializeComponent(); _DbBrowser = dbBrowser; _PoemAudio = poemAudio; _PoemAudioPlayer = new PoemAudioPlayer(); _PoemAudioPlayer.PlaybackStarted += new EventHandler(_PoemAudioPlayer_PlaybackStarted); _PoemAudioPlayer.PlaybackStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(_PoemAudioPlayer_PlaybackStopped); _Modified = false; _Saved = false; _SyncOrder = -1; _LastSearchText = ""; if (poemAudio.SyncArray != null) { _VerseMilisecPositions = new List <PoemAudio.SyncInfo>(poemAudio.SyncArray); } else { _VerseMilisecPositions = new List <PoemAudio.SyncInfo>(); } _PoemVerses = _DbBrowser.GetVerses(poemAudio.PoemId).ToArray(); EnableButtons(); }
/// <summary> /// پخش و ایست پخش فایل صوتی /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlayStop_Click(object sender, EventArgs e) { if (_PoemAudioPlayer != null) { if (_PoemAudioPlayer.IsPlaying) { _PoemAudioPlayer.StopPlayBack(); return; } } if (grdList.SelectedRows.Count == 0) { MessageBox.Show("لطفاً ردیفی را انتخاب کنید."); return; } if (_PoemAudioPlayer == null) { _PoemAudioPlayer = new PoemAudioPlayer(); _PoemAudioPlayer.PlaybackStarted += new EventHandler(_PoemAudioPlayer_PlaybackStarted); _PoemAudioPlayer.PlaybackStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(_PoemAudioPlayer_PlaybackStopped); } PoemAudio poemAudio = grdList.SelectedRows[0].Tag as PoemAudio; if (!_PoemAudioPlayer.BeginPlayback(poemAudio)) { btnPlayStop.Text = "پخش"; btnPlayStop.Image = Properties.Resources.play16; MessageBox.Show("خطایی در پخش فایل صوتی رخ داد. لطفا چک کنید فایل در مسیر تعیین شده قرار داشته باشد."); } if (poemAudio != null && poemAudio.SyncArray != null && poemAudio.SyncArray[0].VerseOrder == -1) { _PoemAudioPlayer.PositionInMiliseconds = poemAudio.SyncArray[0].AudioMiliseconds; } }
public SyncPoemAudio(DbBrowser dbBrowser, PoemAudio poemAudio) { InitializeComponent(); _DbBrowser = dbBrowser; _PoemAudio = poemAudio; _PoemAudioPlayer = new PoemAudioPlayer(); _PoemAudioPlayer.PlaybackStarted += new EventHandler(_PoemAudioPlayer_PlaybackStarted); _PoemAudioPlayer.PlaybackStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(_PoemAudioPlayer_PlaybackStopped); _Modified = false; _Saved = false; _SyncOrder = -1; _LastSearchText = ""; _Modifying = false; _PoemVerses = _DbBrowser.GetVerses(poemAudio.PoemId).ToArray(); if (poemAudio.SyncArray != null) { _VerseMilisecPositions = new List <PoemAudio.SyncInfo>(poemAudio.SyncArray); if (_VerseMilisecPositions.Count > 0 && _VerseMilisecPositions[_VerseMilisecPositions.Count - 1].VerseOrder != (_PoemVerses[_PoemVerses.Length - 1]._Order - 1) ) { if (MessageBox.Show("آیا تمایل دارید همگامسازی را از آخرین نقطهٔ همگام شده ادامه دهید؟", "تأییدیه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading) == DialogResult.Yes) { if (!_PoemAudioPlayer.BeginPlayback(_PoemAudio)) { MessageBox.Show("خطایی در پخش فایل صوتی رخ داد. لطفا چک کنید فایل در مسیر تعیین شده قرار داشته باشد."); } else { _Modifying = true; btnPlayPause.Text = "توقف"; btnPlayPause.Image = Properties.Resources.pause; timer.Start(); trackBar.Maximum = _PoemAudioPlayer.TotalTimeInMiliseconds; _PoemAudioPlayer.PositionInMiliseconds = _VerseMilisecPositions[_VerseMilisecPositions.Count - 1].AudioMiliseconds; _TrackbarValueSetting = true; trackBar.Value = _PoemAudioPlayer.PositionInMiliseconds; _TrackbarValueSetting = false; trackBar.Enabled = true; btnPlayPause_Click(null, null); _SyncOrder = _VerseMilisecPositions[_VerseMilisecPositions.Count - 1].VerseOrder; if (_SyncOrder >= 0 && _SyncOrder < _PoemVerses.Length) { if (_SyncOrder < _PoemVerses.Length - 1) { lblNextVerse.Text = "مصرع بعد: " + _PoemVerses[_SyncOrder + 1]._Text; } else { lblNextVerse.Text = "این مصرع آخر است."; } lblVerse.Text = _PoemVerses[_VerseMilisecPositions[_SyncOrder].VerseOrder]._Text; } } } } } else { _VerseMilisecPositions = new List <PoemAudio.SyncInfo>(); } EnableButtons(); }