private void FromCursor_Click(object sender, RoutedEventArgs e) { var toStart = new TimeSpan(); int toPlayIndex = Textbox.CaretIndex; int lineIndex = Textbox.GetLineIndexFromCharacterIndex(toPlayIndex); String text = Textbox.GetLineText(lineIndex); for (int i = 0; i < timesForNote.Count; i++) { if (timesForNote[i].note.Contains(text)) { if (i > 0) { toStart = timesForNote[i - 1].occurance; } else { toStart = new TimeSpan(0); } } } string textArchive = textBackup; forUseByBackgroundWorker forPlayback = new forUseByBackgroundWorker(toStart, savedRecordingAs); ClassPlayer.Open(new Uri(savedRecordingAs)); // play.Open(new Uri(@"C:\SAMProjects\NoteRecorder\MicAndNotes\MicAndNotes\bin\Release6f6e0b14-623b-4c87-9cfd-eb3cf49fbf0c.wav")); ClassPlayer.Position = toStart; ClassPlayer.Play(); //bw.RunWorkerAsync(forPlayback); ThreadPool.QueueUserWorkItem(o => { shouldContinue = true; int counter = 0; var playBackStopwatch = new Stopwatch(); playBackStopwatch.Start(); while (shouldContinue) { Dispatcher.BeginInvoke(new Action(() => { try { if (playBackStopwatch.Elapsed + toStart < timesForNote[counter].occurance) { Textbox.Text = timesForNote[counter].note; theSlider.Value = timesForNote[counter].occurance.Ticks; } else { counter++; } } catch (Exception) { shouldContinue = false; Textbox.Text = textArchive; Textbox.ScrollToEnd(); theSlider.Value = 0; } })); Thread.Sleep(1); } }); }
private void FromCursor_Click(object sender, RoutedEventArgs e) { var toStart = new TimeSpan(); int toPlayIndex = Textbox.CaretIndex; int lineIndex = Textbox.GetLineIndexFromCharacterIndex(toPlayIndex); string text = Textbox.GetLineText(lineIndex); for (int i = 0; i < _timesForNote.Count; i++) { if (_timesForNote[i].Note.Contains(text)) { toStart = i > 0 ? _timesForNote[i - 1].Occurance : new TimeSpan(0); } } string textArchive = _textBackup; _classPlayer.Open(new Uri(_savedRecordingAs)); // play.Open(new Uri(@"C:\SAMProjects\NoteRecorder\MicAndNotes\MicAndNotes\bin\Release6f6e0b14-623b-4c87-9cfd-eb3cf49fbf0c.wav")); _classPlayer.Position = toStart; _classPlayer.Play(); //var play = new MediaPlayer(); //play.Open(new Uri(forPlayback.filePath)); //play.Position = forPlayback.Span; //play.Play(); //bw.RunWorkerAsync(forPlayback); ThreadPool.QueueUserWorkItem(o => { _shouldContinue = true; int counter = 0; var playBackStopwatch = new Stopwatch(); playBackStopwatch.Start(); while (_shouldContinue) { Dispatcher.BeginInvoke(new Action(() => { //theSlider.Value = playBackStopwatch.ElapsedTicks; try { if (playBackStopwatch.Elapsed + toStart < _timesForNote[counter].Occurance) { Textbox.Text = _timesForNote[counter].Note; _currentlyViewedSection = counter; theSlider.Value = _timesForNote[counter].Occurance.Ticks; } else { counter++; } } catch (Exception) { _shouldContinue = false; //Textbox.Text = textArchive; //Textbox.ScrollToEnd(); //theSlider.Value = 0; //_currentlyViewedSection = -1; } })); Thread.Sleep(1); } }); }