This project has moved. For the latest updates, please go here.

This finalizes the application, what is the problem?

Jun 30, 2012 at 8:11 PM
Edited Jun 30, 2012 at 11:15 PM

Hi! I don't speak english good, sorry but I speak spanish.

This is my code, that have a problem. Sometime, it finalize the application with an error (the application stopped working).

The code:

                var t = new Thread(() =>
                {
                    try
                    {
                        sonido.Position = 0; // Reset position... sonido = Properties.Resources.bateria_1
                        var StreamFile = new WaveFileReader(sonido);
                        var time = StreamFile.TotalTime.Milliseconds + 2200;  // the sum is for prevent an error
                        var Channel32 = new WaveChannel32(StreamFile);
                        var waveout = new WaveOut(WaveCallbackInfo.FunctionCallback());

                        waveout.Init(Channel32);
                        waveout.Play();


                        Thread.Sleep(time);

                        waveout.Stop();
                        waveout.Dispose();

                        Thread.CurrentThread.Abort();
                    }
                    catch(IOException e) { 
                        MessageBox.Show("Error: " + e.Message); // this exception e, dont have a description for view the error...
                    }
                });
                t.Name = "Sonido_platillo";
                t.Start();


Thanks!

 

EDIT:

The exeption information is:

 

 

Not controlled NAudio.MmException
  Message=WaveStillPlaying calling waveOutWrite
  Source=NAudio
  StackTrace:
       en NAudio.Wave.WaveOutBuffer.WriteToWaveOut()
       en NAudio.Wave.WaveOutBuffer.OnDone()
       en NAudio.Wave.WaveOut.Callback(IntPtr hWaveOut, WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr, IntPtr dwReserved)
  InnerException: 

 

EDIT 2:

Also sometime, the exeption is: Not a WAVE file - no RIFF header

 

EDIT 3:

Another exeption is:

 

Se detect� FatalExecutionEngineError
Message: El tiempo de ejecuci�n detect� un error irrecuperable. La direcci�n del error fue 0x5766dc02, en el subproceso 0x1d70. El c�digo de error es 0xc0000005. Es posible que este error sea un error de CLR o de partes no seguras y no verificables de c�digo de usuario. Entre los or�genes m�s habituales de este error se encuentran los errores de referencias calculadas para la interoperabilidad COM o PInvoke, que pueden da�ar la pila.

I dont know what is the problem! :(

 

Coordinator
Jul 1, 2012 at 7:53 AM

I recommend you use WaveOutEvent rather than WaveOut with function callbacks, which I have never managed to get working reliably.

Mark

Jul 1, 2012 at 1:57 PM

Thanks for you reply. But I dont know how use the WaveOutEvent with function callbacks. In my Visual Studio, when I use it, dont shown the function PlaybackThread. I see that WaveOutEvent and WaveOut are very similar. How I do bad?

Coordinator
Jul 2, 2012 at 9:52 AM

WaveOutEvent is instead of function callbacks. Just use WaveOutEvent instead of WaveOut