public void CanStop_NonExistantFile_False() { using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName())) { Assert.IsFalse(x.CanStop); } }
public void CanRecord_FileDoesNotExist_True() { using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName())) { Assert.IsTrue(x.CanRecord); } }
public void RecordThenPlay_SmokeTest() { using (var f = new TempFile()) { var w = new BackgroundWorker(); // ReSharper disable once RedundantDelegateCreation w.DoWork += new DoWorkEventHandler((o, args) => SystemSounds.Exclamation.Play()); using (var x = AudioFactory.CreateAudioSession(f.Path)) { x.StartRecording(); w.RunWorkerAsync(); Thread.Sleep(1000); x.StopRecordingAndSaveAsWav(); bool stopped = false; (x as ISimpleAudioWithEvents).PlaybackStopped += (o, args) => { stopped = true; }; var watch = Stopwatch.StartNew(); x.Play(); while (!stopped) { Thread.Sleep(20); Application.DoEvents(); if (watch.ElapsedMilliseconds > 2000) { x.StopPlaying(); Assert.Fail("stop event not received"); } } } } }
public void StopRecording_NotRecording_Throws() { using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName())) { Assert.Throws <ApplicationException>(() => x.StopRecordingAndSaveAsWav()); } }
public void Play_GiveThaiFileName_ShouldHearTwoSounds() { using (var d = new TemporaryFolder("palaso media test")) { var soundPath = d.Combine("ก.wav"); File.Create(soundPath).Close(); using (var f = TempFile.TrackExisting(soundPath)) { var w = new BackgroundWorker(); // ReSharper disable once RedundantDelegateCreation w.DoWork += new DoWorkEventHandler((o, args) => SystemSounds.Exclamation.Play()); using (var x = AudioFactory.CreateAudioSession(f.Path)) { x.StartRecording(); w.RunWorkerAsync(); Thread.Sleep(2000); x.StopRecordingAndSaveAsWav(); } using (var y = AudioFactory.CreateAudioSession(f.Path)) { y.Play(); Thread.Sleep(1000); y.StopPlaying(); } } } }
public void Play_FileDoesNotExist_Throws() { using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName())) { Assert.Throws <FileNotFoundException>(() => x.Play()); } }
public RecordingSession() { _tempFile = new TempFile(); _recorder = AudioFactory.CreateAudioSession(_tempFile.Path); _recorder.StartRecording(); Thread.Sleep(100); }
public void Construct_FileDoesNotExist_DoesNotCreateFile() { var path = Path.GetRandomFileName(); // ReSharper disable once UnusedVariable using (var x = AudioFactory.CreateAudioSession(path)) { } Assert.IsFalse(File.Exists(path)); // File doesn't exist after disposal }
public void Construct_FileDoesExistButEmpty_OK() { using (var f = new TempFile()) { // ReSharper disable once UnusedVariable using (var x = AudioFactory.CreateAudioSession(f.Path)) { } } }
private ISimpleAudioSession RecordSomething(TempFile f) { var x = AudioFactory.CreateAudioSession(f.Path); x.StartRecording(); Thread.Sleep(100); x.StopRecordingAndSaveAsWav(); return(x); }
public void CanRecord_ConstructWithEmptyFile_True() { using (var f = new TempFile()) { using (var x = AudioFactory.CreateAudioSession(f.Path)) { Assert.IsTrue(x.CanRecord); } } }
public void Play_FileEmpty_Throws() { using (var f = new TempFile()) { using (var x = AudioFactory.CreateAudioSession(f.Path)) { Assert.Throws <FileLoadException>(() => x.Play()); } } }
public void Play_DoesPlay() { using (var file = TempFile.FromResource(Resources.finished, ".wav")) { using (var x = AudioFactory.CreateAudioSession(file.Path)) { Assert.DoesNotThrow(() => x.Play()); Assert.DoesNotThrow(() => x.StopPlaying()); } } }
public void IsRecording_WhileRecording_True() { using (var f = new TempFile()) { using (var x = AudioFactory.CreateAudioSession(f.Path)) { x.StartRecording(); Thread.Sleep(100); Assert.IsTrue(x.IsRecording); x.StopRecordingAndSaveAsWav(); } } }
public void Record_DoesRecord() { using (var folder = new TemporaryFolder("Record_DoesRecord")) { string fpath = Path.Combine(folder.Path, "dump.ogg"); using (var x = AudioFactory.CreateAudioSession(fpath)) { Assert.DoesNotThrow(() => x.StartRecording()); Assert.IsTrue(x.IsRecording); Thread.Sleep(1000); Assert.DoesNotThrow(() => x.StopRecordingAndSaveAsWav()); } } }
public void RecordAndStop_FileAlreadyExists_FileReplaced() { using (var f = new TempFile()) { var oldInfo = new FileInfo(f.Path); var oldLength = oldInfo.Length; Assert.AreEqual(0, oldLength); var oldTimestamp = oldInfo.LastWriteTimeUtc; using (var x = AudioFactory.CreateAudioSession(f.Path)) { x.StartRecording(); Thread.Sleep(1000); x.StopRecordingAndSaveAsWav(); } var newInfo = new FileInfo(f.Path); Assert.Greater(newInfo.LastWriteTimeUtc, oldTimestamp); Assert.Greater(newInfo.Length, oldLength); } }
public void Play_DoesPlayMp3_SmokeTest() { // file disposed after playback stopped var file = TempFile.FromResource(Resources.ShortMp3, ".mp3"); using (var x = AudioFactory.CreateAudioSession(file.Path)) { (x as ISimpleAudioWithEvents).PlaybackStopped += (e, f) => { Debug.WriteLine(f); Thread.Sleep(100); file.Dispose(); }; Assert.That(x.IsPlaying, Is.False); Assert.DoesNotThrow(() => x.Play()); Assert.That(x.IsPlaying, Is.True); Assert.DoesNotThrow(() => x.StopPlaying()); Assert.That(x.IsPlaying, Is.False); } }
public void RecordThenPlay_SmokeTest() { using (var f = new TempFile()) { var w = new BackgroundWorker(); // ReSharper disable once RedundantDelegateCreation w.DoWork += new DoWorkEventHandler((o, args) => SystemSounds.Exclamation.Play()); using (var x = AudioFactory.CreateAudioSession(f.Path)) { x.StartRecording(); w.RunWorkerAsync(); Thread.Sleep(1000); x.StopRecordingAndSaveAsWav(); bool stopped = false; bool isPlayingInEventHandler = false; (x as ISimpleAudioWithEvents).PlaybackStopped += (o, args) => { // assert here is swallowed, probably because not receiving exceptions from background worker. // We want to check that isPlaying is false even during the event handler. isPlayingInEventHandler = x.IsPlaying; stopped = true; }; var watch = Stopwatch.StartNew(); x.Play(); while (!stopped) { Thread.Sleep(20); Application.DoEvents(); if (watch.ElapsedMilliseconds > 2000) { x.StopPlaying(); Assert.Fail("stop event not received"); } } // After playback is stopped we shouldn't be reporting that it is playing Assert.That(isPlayingInEventHandler, Is.False); Assert.That(x.IsPlaying, Is.False); } } }
/// <summary> /// Used for a practical validation of audio session record and playback. /// Hold the button down while saying something; release to hear playback. /// Should see a "play started" dialog immediately after releasing mouse, /// and "play stopped" when it has all played. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void recordPlayButton_MouseDown(object sender, MouseEventArgs e) { _mouseDownFlag = true; using (var tempFile = TempFile.WithExtension(".wav")) using (var session = AudioFactory.CreateAudioSession(tempFile.Path)) { session.StartRecording(); while (_mouseDownFlag) { Thread.Sleep(10); Application.DoEvents(); } session.StopRecordingAndSaveAsWav(); (session as ISimpleAudioWithEvents).PlaybackStopped += (o, args) => { this.Invoke((Action)(() => MessageBox.Show("play stopped"))); }; session.Play(); MessageBox.Show("play started"); } }
public void Record_LongRecording() { using (var folder = new TemporaryFolder("Record_LongRecording")) { string fpath = Path.Combine(folder.Path, "long.wav"); using (var x = AudioFactory.CreateAudioSession(fpath)) { SystemSounds.Beep.Play(); Assert.DoesNotThrow(() => x.StartRecording()); Assert.IsTrue(x.IsRecording); Thread.Sleep(10000); // Records 10 seconds Assert.DoesNotThrow(() => x.StopRecordingAndSaveAsWav()); SystemSounds.Beep.Play(); Assert.IsTrue(x.CanPlay); Assert.DoesNotThrow(() => x.Play()); Thread.Sleep(4000); // Plays the first 4 seconds Assert.DoesNotThrow(() => x.StopPlaying()); Thread.Sleep(500); // Pause Assert.DoesNotThrow(() => x.Play()); Thread.Sleep(6000); // Plays the first 6 seconds Assert.DoesNotThrow(() => x.StopPlaying()); } } }
public void Construct_FileDoesNotExist_OK() { // ReSharper disable once UnusedVariable using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName())) { } }