Пример #1
0
 public void CanStop_NonExistantFile_False()
 {
     using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName()))
     {
         Assert.IsFalse(x.CanStop);
     }
 }
Пример #2
0
 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");
                        }
                    }
                }
            }
        }
Пример #4
0
 public void StopRecording_NotRecording_Throws()
 {
     using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName()))
     {
         Assert.Throws <ApplicationException>(() => x.StopRecordingAndSaveAsWav());
     }
 }
Пример #5
0
        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();
                    }
                }
            }
        }
Пример #6
0
 public void Play_FileDoesNotExist_Throws()
 {
     using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName()))
     {
         Assert.Throws <FileNotFoundException>(() => x.Play());
     }
 }
Пример #7
0
 public RecordingSession()
 {
     _tempFile = new TempFile();
     _recorder = AudioFactory.CreateAudioSession(_tempFile.Path);
     _recorder.StartRecording();
     Thread.Sleep(100);
 }
Пример #8
0
        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
        }
Пример #9
0
 public void Construct_FileDoesExistButEmpty_OK()
 {
     using (var f = new TempFile())
     {
         // ReSharper disable once UnusedVariable
         using (var x = AudioFactory.CreateAudioSession(f.Path)) { }
     }
 }
Пример #10
0
        private ISimpleAudioSession RecordSomething(TempFile f)
        {
            var x = AudioFactory.CreateAudioSession(f.Path);

            x.StartRecording();
            Thread.Sleep(100);
            x.StopRecordingAndSaveAsWav();
            return(x);
        }
Пример #11
0
 public void CanRecord_ConstructWithEmptyFile_True()
 {
     using (var f = new TempFile())
     {
         using (var x = AudioFactory.CreateAudioSession(f.Path))
         {
             Assert.IsTrue(x.CanRecord);
         }
     }
 }
Пример #12
0
 public void Play_FileEmpty_Throws()
 {
     using (var f = new TempFile())
     {
         using (var x = AudioFactory.CreateAudioSession(f.Path))
         {
             Assert.Throws <FileLoadException>(() => x.Play());
         }
     }
 }
Пример #13
0
 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());
         }
     }
 }
Пример #14
0
 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();
         }
     }
 }
Пример #15
0
 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());
         }
     }
 }
Пример #16
0
 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);
     }
 }
Пример #17
0
        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);
            }
        }
Пример #18
0
        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);
                }
            }
        }
Пример #19
0
 /// <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");
         }
 }
Пример #20
0
 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());
         }
     }
 }
Пример #21
0
 public void Construct_FileDoesNotExist_OK()
 {
     // ReSharper disable once UnusedVariable
     using (var x = AudioFactory.CreateAudioSession(Path.GetRandomFileName())) { }
 }