This project has moved and is read-only. For the latest updates, please go here.

Simultaneous Recording and Playing

Oct 14, 2009 at 3:37 PM

Hi All!
I am working on an application that will enable users to tag content of sound files while recording them.Therefore I need to be able to listen to recordings while they are being recorded. Ideally it would be possible to navigate the file and listen at random points
The recordings lasts for several hours
I see some ways of doing this:

1. Ideally  play and listen to the actual file being recorded. I have tried but my mediaplayer refuses to play an open file.

2. Record short temporary files and save them and concatenate them to a growing temporary file to be used only for listening.
   If the temporay files are relatively short eg 1 minute that would be OK I think.

I have tried to record with nAudio and the first file opens and closes OK. But when I have closed it and try to directly start a new recording I receive an error message:

I have been unable to catch the error in my code.

System.NullReferenceException was unhandled
  Message="Objektreferensen har inte angetts till en instans av ett objekt."
       vid NAudio.Wave.WaveInStream.Callback(IntPtr waveInHandle, WaveInMessage message, Int32 userData, WaveHeader waveHeader, Int32 reserved)
       vid NAudio.Wave.WaveInStream.WaveInWindow.WndProc(Message& m)
       vid System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       vid System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       vid System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       vid System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       vid System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       vid System.Windows.Forms.Application.Run(ApplicationContext context)
       vid Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       vid Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       vid Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       vid Mediarecorder.My.MyApplication.Main(String[] Args) i 17d14f5c-a337-4978-8281-53493378c1071.vb:rad 81
       vid System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       vid System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       vid Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       vid System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       vid System.Threading.ThreadHelper.ThreadStart()

    I assume that I am missing something  crucial but my idea was to start and stop the recording based on a timer. When the file was closed I would create a new filename for the output and start a new recording with the new name and so on until I manually stop the recording.

Any ideas what I should think about to get this to work?



Oct 16, 2009 at 7:48 AM

Hi Gunnar,

are you using the latest NAudio (1.3). WaveInStream is marked as obsolete. You should use WaveIn instead.

Also, wait for the RecordingStopped event after calling Stop to be sure everything has finished