App crash using Naudio.

Jul 28 at 9:14 AM
Hi Mark,

I developer a Media player using naudio software.If we play single player then no problem arise but if we play multiple instances the app randomly crashing.

How to solve the problem please suggest.
Coordinator
Jul 28 at 4:02 PM
Well, what exception are you getting? What is the error message? Where does the stack trace point to? What output device model are you using?
Jul 29 at 5:53 AM
Edited Jul 29 at 6:06 AM
I not get any error on the my Audioplaybackpanel.cs class.The moto of my project is the player continue to play all day and night.Song start from cue in time and end in cue out time.

here is the crash report
Faulting application name: BMAsia Media Player.exe, version: 1.0.0.0, time stamp: 0x53ce37ae
Faulting module name: comctl32.dll, version: 6.10.7601.17514, time stamp: 0x4ce7b71c
Exception code: 0xc00000fd


We use Gigaport HD version3 for sound device it is a multi cahnnel sound port.

``` private void TimerEventProcessor(Object myObject,EventArgs myEventArgs)
    {
        try
        {
            if (objAudioPlaybackPanel.CurrentlyActiveWaveOut1 == true)
            {
                if (objAudioPlaybackPanel.lstSongDetails.Items.Count <= 0)
                {
                    return;
                }
                if (objAudioPlaybackPanel.waveOut != null && objAudioPlaybackPanel.fileWaveStream != null && objAudioPlaybackPanel.waveChannel != null)
                {
                    TimeSpan currentTime = (objAudioPlaybackPanel.waveOut.PlaybackState == PlaybackState.Stopped) ? TimeSpan.Zero : objAudioPlaybackPanel.fileWaveStream.CurrentTime;
                    TimeSpan remainingTime = (objAudioPlaybackPanel.waveOut.PlaybackState == PlaybackState.Stopped) ? TimeSpan.Zero : TimeSpan.FromSeconds(objAudioPlaybackPanel.waveChannel.FadeOutSongTime) - objAudioPlaybackPanel.fileWaveStream.CurrentTime;
                    if ((objAudioPlaybackPanel.waveChannel2 != null) && ((int)Math.Round(objAudioPlaybackPanel.fileWaveStream2.CurrentTime.TotalSeconds) >= (int)Math.Round(objAudioPlaybackPanel.fileWaveStream2.TotalTime.TotalSeconds))) // (int)Math.Round(waveChannel2.FadeOutSongTime)
                    {
                        objAudioPlaybackPanel.CloseWaveOut2();
                        objAudioPlaybackPanel.waveChannel2 = null;
                    }
                    if (objAudioPlaybackPanel.waveChannel2 != null)
                    {
                        objAudioPlaybackPanel.waveChannel2.Volume = objAudioPlaybackPanel.waveChannel2.Volume * 0.7F; //volumeSlider1.Volume                            
                    }

                    if (objAudioPlaybackPanel.waveChannel.CurrentSongTime >= (int)Math.Round(objAudioPlaybackPanel.waveChannel.FadeOutSongTime - 0.6) && objAudioPlaybackPanel.ssss == false && objAudioPlaybackPanel.intoLoop == false) //- 1.5
                    {
                        objAudioPlaybackPanel.intoLoop = true;

                    }
                    if (objAudioPlaybackPanel.waveChannel.CurrentSongTime >= (int)Math.Round(objAudioPlaybackPanel.waveChannel.FadeOutSongTime - 0.6) && objAudioPlaybackPanel.ssss == false) //- 1.5
                    {
                        if (objAudioPlaybackPanel.waveChannel.CurrentSongTime != 0.0)
                        {
                            objAudioPlaybackPanel.intoLoop = false;


                            if (objAudioPlaybackPanel.lstSongDetails.Items.Count > 0)//changes
                            {
                                //if (waveChannel.CurrentSongTime != 0.0)
                                //{
                                objAudioPlaybackPanel.lstSongDetails.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                                {
                                    objAudioPlaybackPanel.lstSongDetails.Items.RemoveAt(0);
                                }));
                                //}
                            }

                            for (int i = 0; i < 2 - objAudioPlaybackPanel.lstSongDetails.Items.Count; i++)
                            {
                                objAudioPlaybackPanel.AddNewSongOnListView();
                            }

                            if (objAudioPlaybackPanel.lstSongDetails.Items.Count > 0)
                            {
                                //objAudioPlaybackPanel.fileName = objAudioPlaybackPanel.Application_StartUpPath + "\\Current Song.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\" + objAudioPlaybackPanel.lstSongDetails.Items[0].SubItems[1].Text + ".mp3";// listSongDetails[CurrentPlaysongIndex].Name;
                                objAudioPlaybackPanel.lstSongDetails.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                                {
                                    objAudioPlaybackPanel.fileName = AudioPlaybackPanel.Application_StartUpPath + "\\Current Song.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\" + objAudioPlaybackPanel.lstSongDetails.Items[0].SubItems[1].Text + ".mp3";// listSongDetails[CurrentPlaysongIndex].Name;
                                }));
                            }
                            if (objAudioPlaybackPanel.fileName.Trim() == "")
                            {
                                objAudioPlaybackPanel.AddNewSongOnListView();
                                objAudioPlaybackPanel.lstSongDetails.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                                {
                                    objAudioPlaybackPanel.fileName = AudioPlaybackPanel.Application_StartUpPath + "\\Current Song.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\" + objAudioPlaybackPanel.lstSongDetails.Items[0].SubItems[1].Text + ".mp3";// listSongDetails[CurrentPlaysongIndex].Name;
                                }));
                            }
                            else
                            {
                                if (!File.Exists(objAudioPlaybackPanel.fileName))
                                {
                                    objAudioPlaybackPanel.lstSongDetails.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                                    {
                                        objAudioPlaybackPanel.fileName = AudioPlaybackPanel.Application_StartUpPath + "\\Songs.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\" + objAudioPlaybackPanel.lstSongDetails.Items[0].SubItems[1].Text + ".mp3";
                                    }));
                                    objAudioPlaybackPanel.DecryptCurrentPlayFile();
                                }
                            }
                            objAudioPlaybackPanel.lstSongDetails.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                            {
                                if (objAudioPlaybackPanel.lstSongDetails.Items.Count <= 0)
                                {
                                    return;
                                }
                            }));
                            if (objAudioPlaybackPanel.RestartPlayerAfterBreak == false)
                            {                                

                                objAudioPlaybackPanel.PlayNextSong2();
                                //objAudioPlaybackPanel.CloseWaveOut();//07-07-2014
                                //objAudioPlaybackPanel.waveChannel = null;//07-07-2014
                            }
                            else
                            {
                                myTimer.Stop();
                                objAudioPlaybackPanel.timer2.Start();
                                if (objAudioPlaybackPanel.waveOut != null)
                                {
                                    objAudioPlaybackPanel.waveOut.Stop();
                                }
                                if (objAudioPlaybackPanel.waveOut2 != null)
                                {
                                    objAudioPlaybackPanel.waveOut2.Stop();
                                }
                            }
                        }

                    }
                    else
                    {
                        try
                        {
                            objAudioPlaybackPanel.songPositionSlider1.CuttentTime = (int)((currentTime.TotalSeconds * 580) / objAudioPlaybackPanel.songPositionSlider1.SongLength);
                        }
                        catch (Exception ex)
                        {
                            objAudioPlaybackPanel.obj_Global.WriteErrorLogFile("AudioPlayBackPanel", "timer1_Tick()" + objAudioPlaybackPanel.objMainForm.PlayerName, ex.Message);
                            objAudioPlaybackPanel.lstSongDetails.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                            {
                                objAudioPlaybackPanel.fileName = AudioPlaybackPanel.Application_StartUpPath + "\\Current Song.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\" + objAudioPlaybackPanel.lstSongDetails.Items[0].SubItems[1].Text + ".mp3";
                            }));
                            if (!File.Exists(objAudioPlaybackPanel.fileName))
                            {
                                objAudioPlaybac
Jul 29 at 6:14 AM
Edited Jul 31 at 7:58 AM
Here is the one error and this error come after 1 or two days not instantly so no issue found on on debugging:

WaveOutBuffer class - WriteToWaveOut() - Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

WaveOutEvent - Init() - AlreadyAllocated calling waveOutOpen
WaveOutEvent - PlaybackThread() - Object reference not set to an instance of an object.
InvalidParameter calling acmStreamClose


here is the code to close waveout:
  public void CloseWaveOut2()
        {
            try
            {
                if (waveOut2 != null)
                {
                    waveOut2.Stop();
                }
                if (fileWaveStream2 != null)
                {
                    // this one really closes the file and ACM conversion
                    fileWaveStream2.Dispose();
                    wavechannel32_2.Dispose();
                    compress2.Dispose();
                    // this.setVolumeDelegate = null;
                    // this.setNormalizeDelegate = null;
                }
                if (waveOut2 != null)
                {
                    waveOut2.Dispose(true);
                    waveOut2 = null;
                }
            }
            catch (Exception ex)
            {
                obj_Global.WriteErrorLogFile("AudioPlayBackPanel", "CloseWaveOut2()", ex.Message);
            }
        }
We can't dispose wave out object because of crossover of two song.Crossover means we remove silent bit first and last of the song.Song start from (cue in(remove start silance bit)) time and end in (cue out(remove last silance bit)) time.If first song reach to cue out time then second waveout2 object create and start the second song.Then decrease the volume of first song.Then if First song Over or equal of total time then we release the first object.Then same process follow.

Now problem is that after couple of days(Not instantly) One or multiple player stops due to this error:

7/31/2014 11:02:15 AM - WaveOutEvent - Init() - AlreadyAllocated calling waveOutOpen
7/31/2014 11:02:15 AM - WaveOutEvent - PlaybackThread() - Object reference not set to an instance of an object.
We create two wave out object.
public WaveOutEvent waveOut;
public WaveOutEvent waveOut2;

How to overcome this scenario please suggest me immediately.

Do you know why this error occurred in windows?

"A problem caused this program to stop interacting with Windows.This error Hags all player.
Coordinator
Jul 31 at 12:26 PM
Are the two instances of WaveOutEvent both playing to the same soundcard? I would recommend just having one WaveOutEvent and creating a never-ending sampleprovider that handles the crossover of song (eg with FadeInOutSampleProvider).

Another thing you could try is a different output model such as DirectSoundOut and see if that has the same issue.
Jul 31 at 1:57 PM
Edited Jul 31 at 2:29 PM
Hi Mark,

You recommended me "creating a never-ending sampleprovider that handles the crossover of song (eg with FadeInOutSampleProvider)". I have a question that How to use Sample provider that handled crossover of song(eg with FadeInOutSampleProvider)?

How We can use "DirectSoundOut" class because we can't find out device latency and device number using this class:
 [Export(typeof(IOutputDevicePlugin))]
    class WaveOutPlugin : IOutputDevicePlugin
    {
        private WaveOutSettingsPanel waveOutSettingsPanel;

        public WaveOutEvent CreateDevice(int latency, int SelectedDeviceNumber)
        {
            WaveOutEvent device;
            WaveCallbackStrategy strategy = waveOutSettingsPanel.CallbackStrategy;
            if (strategy == WaveCallbackStrategy.Event)
            {
                var waveOut = new WaveOutEvent();
                waveOut.DeviceNumber = SelectedDeviceNumber;
                waveOut.DesiredLatency = latency;
                device = waveOut;
            }
            else
            {
                //WaveCallbackInfo callbackInfo = strategy == WaveCallbackStrategy.NewWindow ? WaveCallbackInfo.NewWindow() : WaveCallbackInfo.FunctionCallback();
                WaveOutEvent outputDevice = new WaveOutEvent();
                outputDevice.DeviceNumber = SelectedDeviceNumber;
                outputDevice.DesiredLatency = latency;
                device = outputDevice;
                outputDevice=null;
            }
            // TODO: configurable number of buffers

            return device;
        }
Coordinator
Jul 31 at 8:37 PM
Yes, DirectSound doesn't work with device numbers. But we are trying to narrow down your issue, so try a long-running playback with it. Also, have you tried a long-running playback with WaveOutEvent just being fed by a SignalGenerator? How long can that play for before a crash?

To handle crossover with sample providers, you can make use of MixingSampleProvider, or write your own mixer if you prefer.

Mark
Aug 1 at 7:18 AM
Edited Aug 1 at 10:33 AM
Hi mark,

We can't use directSounddevice class because we working on multiple channel so we need multiple sound driver.(Please suggest how to pass Guid device from audio playbackpanel).

Yes we have tried a long-running playback with WaveOutEvent But player crash,hangs or stop after1, 2,3 or 4 days But not all player only two or three player. But we can't understand "being fed by a SignalGenerator".

We Implement crossover using Timer control.Have you provide any code that implement Crossover using timer control.Please help me.We are new in the sound code.

Here is the code for waveout creation
 public void CreateWaveOut()
        {
            try
            {
                CloseWaveOut();
                int latency = (int)comboBoxLatency.SelectedItem;
                this.waveOut = SelectedOutputDevicePlugin.CreateDevice(latency, objsetting.outputdevice);
                if (listSongDetails.Count > 0)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        if (lstSongDetails.Items.Count > 0)//changes
                        {
                            lblCurrentPlaying.Text = lstSongDetails.Items[0].SubItems[1].Text.Replace(".mp3", "");
                        }// listSongDetails[CurrentPlaysongIndex].Name;
                    }));
                }
            }
            catch (Exception ex)
            {
                obj_Global.WriteErrorLogFile("AudioPlayBackPanel", "CreateWaveOut()" + objMainForm.PlayerName, ex.Message);
            }
        }
Now my code:
 public void CreateWaveOut()
        {
            try
            {
                CloseWaveOut();
                int latency = (int)comboBoxLatency.SelectedItem;
                //this.waveOut = SelectedOutputDevicePlugin.CreateDevice(latency, objsetting.outputdevice);
                this.waveOut = new DirectSoundOut(latency);
                if (listSongDetails.Count > 0)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        if (lstSongDetails.Items.Count > 0)//changes
                        {
                            lblCurrentPlaying.Text = lstSongDetails.Items[0].SubItems[1].Text.Replace(".mp3", "");
                        }// listSongDetails[CurrentPlaysongIndex].Name;
                    }));
                }
            }
            catch (Exception ex)
            {
                obj_Global.WriteErrorLogFile("AudioPlayBackPanel", "CreateWaveOut()" + objMainForm.PlayerName, ex.Message);
            }
        }
Coordinator
Aug 1 at 12:08 PM
The NAudio demo includes demonstrations of how to use DirectSoundOut. Use DirectSoundOut.Devices to find the available devices on your system.

By signalgenerator I mean use the SignalGenerator that is part of NAudio. Something like this (pseudocode):
var player = new WaveOutEvent();
var signalGenerator = new SignalGenerator();
player.Init(signalGenerator);
player.Play();
and see how long that can go for. If there is an error in the interop / pinning somewhere, then this simple code should also fail over time. Otherwise it is to do with using multiple playback devices.

I'd also recommend if at all possible you invest in a month's pluralsight subscription and watch my digital audio fundamentals and Audio programming with NAudio courses. It's 10 hours of material and will give you a much stronger understanding of how to develop audio applications.
Aug 2 at 10:42 AM
Hi Mark,
I want to know any method or event to catch abnormal stop player.Please suggest.
Coordinator
Aug 2 at 11:01 AM
are you subscribing to the PlaybackStopped event. That is how you detect playback stopped in NAudio
Aug 2 at 12:34 PM
    void Assemble_list_of_all_devices()
    {
        input_devices_count = 0;
        output_devices_count = 0;
        //---------------------wasapi---------------------
        if (wasapi_available)
        {
            var enumerator = new MMDeviceEnumerator();
            var endPoints = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);
            foreach (MMDevice endPoint in endPoints)
            {
                if (input_devices_count >= input_devices.Length) continue;
                input_devices[input_devices_count].clean();
                input_devices[input_devices_count].mode = 2;
                input_devices[input_devices_count].wasapi_mmdevice = endPoint;
                input_devices[input_devices_count].wasapi_id = endPoint.ID;
                input_devices[input_devices_count].title = endPoint.FriendlyName;
                //input_devices[input_devices_count].title += endPoint.DeviceFriendlyName;
                input_devices_count++;
            }
            endPoints = null;
            endPoints = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
            foreach (MMDevice endPoint in endPoints)
            {
                if (output_devices_count >= output_devices.Length) continue;
                output_devices[output_devices_count].clean();
                output_devices[output_devices_count].mode = 2;
                output_devices[output_devices_count].wasapi_mmdevice = endPoint;
                output_devices[output_devices_count].wasapi_id = endPoint.ID;
                output_devices[output_devices_count].title = endPoint.FriendlyName;
                //output_devices[output_devices_count].title += endPoint.DeviceFriendlyName;
                output_devices_count++;
            }

        }

        //------------------directsound-------------------
        if (true)//if ds_avaiable
        {
            int _dso_count = DirectSoundOut.Devices.Count();
            foreach (DirectSoundDeviceInfo di in DirectSoundOut.Devices)
            {
                if (output_devices_count >= output_devices.Length) continue;
                output_devices[output_devices_count].clean();
                output_devices[output_devices_count].mode = 1;
                output_devices[output_devices_count].dsguid = di.Guid;
                output_devices[output_devices_count].title = di.Description;
                output_devices_count++;
            }
        }

        //--------------------wave in---------------------
        if (true)//if wave_in_avaiable
        {
            for (int i = 0; i < WaveInEvent.DeviceCount; i++)
            {
                if (input_devices_count >= input_devices.Length) continue;
                WaveInCapabilities capabilities_i = WaveInEvent.GetCapabilities(i);
                input_devices[input_devices_count].clean();
                input_devices[input_devices_count].mode = 0;
                input_devices[input_devices_count].wave_device_ind = i;
                input_devices[input_devices_count].dsguid = capabilities_i.ProductGuid;
                input_devices[input_devices_count].title = capabilities_i.ProductName;
                input_devices_count++;
            }
        }

    }

////////////////////////
    device_item[] input_devices = null;
    device_item[] output_devices = null;
    int input_devices_count = 0;
    int output_devices_count = 0;
//---------
        input_devices = new device_item[129];
        output_devices = new device_item[129];
        for (int i = 0; i < input_devices.Length; i++) { input_devices[i] = new device_item(); }
        for (int i = 0; i < output_devices.Length; i++) { output_devices[i] = new device_item(); }


    public class device_item
    {
        public device_item()
        {
            //init_device_item();
        }
        public int mode;  //0 wave, 1 directsound, 2 wasapi
        public int wave_device_ind;
        public Guid dsguid;
        public string title;
        public string wasapi_id;
        public MMDevice wasapi_mmdevice;

        public void clean()
        {
            mode = -1;
            wave_device_ind = 0;
            dsguid = Guid.Empty;
            //isdefault = false;
            title = "";
            wasapi_id = "";
            wasapi_mmdevice = null;
        }
        public void copy_from(device_item source_item)
        {
            this.mode = source_item.mode;
            this.wave_device_ind = source_item.wave_device_ind;
            this.dsguid = source_item.dsguid;
            //isdefault = ;
            this.title = source_item.title;
            this.wasapi_id = source_item.wasapi_id;
            this.wasapi_mmdevice = source_item.wasapi_mmdevice;
        }
    }

            //---------on show selection combobox

            int o_found_ind = -1;
            int i_found_ind = -1;

            f2.output_device_comboBox.Items.Clear();

            for (int i = 0; i < output_devices_count; i++)
            {

                if (output_devices[i].mode == 1)
                {
                    f2.output_device_comboBox.Items.Add("[DirectSound] " + output_devices[i].title);
                    if (current_output_device_data.mode == output_devices[i].mode) if (current_output_device_data.dsguid == output_devices[i].dsguid) o_found_ind = i;
                }
                else if (output_devices[i].mode == 2)
                {
                    f2.output_device_comboBox.Items.Add("[WasApi] " + output_devices[i].title);
                    if (current_output_device_data.mode == output_devices[i].mode) if (current_output_device_data.wasapi_id == output_devices[i].wasapi_id) o_found_ind = i;
                }
                else
                {
                    //f2.output_device_comboBox.Items.Add(output_devices[i].title);
                }
            }

            //find index in list of all devices
            if (o_found_ind >= 0) f2.output_device_comboBox.SelectedIndex = o_found_ind;


            f2.input_device_comboBox.Items.Clear();
            for (int i = 0; i < input_devices_count; i++)
            {
                if (input_devices[i].mode == 0)
                {
                    f2.input_device_comboBox.Items.Add("[WaveIn] " + input_devices[i].title);
                    if (current_input_device_data.mode == input_devices[i].mode)
                    {
                        if (current_input_device_data.wave_device_ind == input_devices[i].wave_device_ind) i_found_ind = i;
                    }
                }
                else if (input_devices[i].mode == 2)
                {
                    f2.input_device_comboBox.Items.Add("[WasApi] " + input_devices[i].title);
                    if (current_input_device_data.mode == input_devices[i].mode) if (current_input_device_data.wasapi_id == input_devices[i].wasapi_id) i_found_ind = i;
                }
                else
                {
                    //f2.input_device_comboBox.Items.Add(input_devices[i].title);
                }
            }
            if ((current_input_mode == 0) && (i_found_ind == -1))   //if index and name mismatch, try just name
            {
                for (int i = 0; i < input_devices_count; i++)
                {
                    if (input_devices[i].mode == 0) if (current_input_device_data.title == input_devices[i].title) i_found_ind = i;
                }
            }
            if (i_found_ind >= 0) f2.input_device_comboBox.SelectedIndex = i_found_ind;
Aug 2 at 12:36 PM
            //on change device button click
            if (f2.input_device_comboBox.SelectedIndex != i_found_ind) change_input_dev_parameters = true;
            if (f2.output_device_comboBox.SelectedIndex != o_found_ind) change_output_dev_parameters = true;
            if (f2.output_device_latency_changed) change_output_dev_parameters = true;


            if (change_output_dev_parameters)
            {
                int new_ind = f2.output_device_comboBox.SelectedIndex;
                if (output_devices[new_ind].mode == 1)
                {
                    Open_dso_device(output_devices[new_ind]);
                    current_output_device_data.copy_from(output_devices[new_ind]);
                    current_output_mode = output_devices[new_ind].mode;
                }
                else if (output_devices[new_ind].mode == 2)
                {
                    Open_wasapiout_device(output_devices[new_ind]);
                    current_output_device_data.copy_from(output_devices[new_ind]);
                    current_output_mode = output_devices[new_ind].mode;
                }//else show warning?
            }

            if (change_input_dev_parameters)
            {
                int new_ind = f2.input_device_comboBox.SelectedIndex;
                if (input_devices[new_ind].mode == 0)
                {
                    Open_wavein_device(input_devices[new_ind]);
                    current_input_device_data.copy_from(input_devices[new_ind]);
                    current_input_mode = input_devices[new_ind].mode;
                }
                else if (input_devices[new_ind].mode == 2)
                {
                    Open_wasapicapture_device(input_devices[new_ind]);
                    current_input_device_data.copy_from(input_devices[new_ind]);
                    current_input_mode = input_devices[new_ind].mode;
                }//else show warning?
            }
Aug 2 at 12:48 PM
Edited Aug 2 at 12:52 PM
when loading id from config, if current_device is var outside _devices array, you might need to call this as well before opening wasapi
    void point_wasapicapture(ref device_item dev_temp)
    {
        if (dev_temp.mode != 2) return;
        if (!wasapi_available) return;

        for (int i = 0; i < input_devices_count; i++)
        {
            if (input_devices[i].mode != 2) continue;
            if (input_devices[i].wasapi_id != dev_temp.wasapi_id) continue;
            dev_temp.copy_from(input_devices[i]);
        }
    }
    void point_wasapiout(ref device_item dev_temp)
    {
        if (dev_temp.mode != 2) return;
        if (!wasapi_available) return;

        for (int i = 0; i < output_devices_count; i++)
        {
            if (output_devices[i].mode != 2) continue;
            if (output_devices[i].wasapi_id != dev_temp.wasapi_id) continue;
            dev_temp.copy_from(output_devices[i]);
        }
    }
Aug 4 at 2:05 PM
Edited Aug 5 at 7:36 AM
Hi Mark,

We have testing on all the class Waveoutevent.cs, DirectSoundout.cs class but my app creasing or hanging.I could't understand how to solve this issue. Please help me.After 5 days my application has crashed.



Here is the crash report:
ask Category: (100)
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      JOH-PC
Description:
Faulting application name: BMAsia Media Player.exe, version: 1.0.0.0, time stamp: 0x53ce37ae
Faulting module name: comctl32.dll, version: 6.10.7601.17514, time stamp: 0x4ce7b71c
Exception code: 0xc00000fd
Fault offset: 0x00027209
Faulting process id: 0xe74
Faulting application start time: 0x01cfaba70f6efb4d
Faulting application path: C:\Windows\SysWOW64\BMAsia\BMAsia Media Player.exe
Faulting module path: C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_41e6975e2bd6f2b2\comctl32.dll
Report Id: 07b9f6a9-1b09-11e4-b3bf-00a0c6db3a93
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Application Error" />
    <EventID Qualifiers="0">1000</EventID>
    <Level>2</Level>
    <Task>100</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2014-08-03T12:23:53.000000000Z" />
    <EventRecordID>257269</EventRecordID>
    <Channel>Application</Channel>
    <Computer>JOH-PC</Computer>
    <Security />
  </System>
  <EventData>
    <Data>BMAsia Media Player.exe</Data>
    <Data>1.0.0.0</Data>
    <Data>53ce37ae</Data>
    <Data>comctl32.dll</Data>
    <Data>6.10.7601.17514</Data>
    <Data>4ce7b71c</Data>
    <Data>c00000fd</Data>
    <Data>00027209</Data>
    <Data>e74</Data>
    <Data>01cfaba70f6efb4d</Data>
    <Data>C:\Windows\SysWOW64\BMAsia\BMAsia Media Player.exe</Data>
    <Data>C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_41e6975e2bd6f2b2\comctl32.dll</Data>
    <Data>07b9f6a9-1b09-11e4-b3bf-00a0c6db3a93</Data>
  </EventData>
</Event>
Here is the second crash report:
Log Name:      Application
Source:        Application Error
Date:          8/3/2014 3:39:09 AM
Event ID:      1000
Task Category: (100)
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      JOH-PC
Description:
Faulting application name: BMAsia Media Player.exe, version: 1.0.0.0, time stamp: 0x53ce37ae
Faulting module name: USER32.dll, version: 6.1.7601.17514, time stamp: 0x4ce7ba59
Exception code: 0xc00000fd
Fault offset: 0x0001613f
Faulting process id: 0x80c
Faulting application start time: 0x01cfaba71928bf82
Faulting application path: C:\Windows\SysWOW64\BMAsia\BMAsia Media Player.exe
Faulting module path: C:\Windows\syswow64\USER32.dll
Report Id: 0d1d4bbd-1a85-11e4-b3bf-00a0c6db3a93
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Application Error" />
    <EventID Qualifiers="0">1000</EventID>
    <Level>2</Level>
    <Task>100</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2014-08-02T20:39:09.000000000Z" />
    <EventRecordID>257268</EventRecordID>
    <Channel>Application</Channel>
    <Computer>JOH-PC</Computer>
    <Security />
  </System>
  <EventData>
    <Data>BMAsia Media Player.exe</Data>
    <Data>1.0.0.0</Data>
    <Data>53ce37ae</Data>
    <Data>USER32.dll</Data>
    <Data>6.1.7601.17514</Data>
    <Data>4ce7ba59</Data>
    <Data>c00000fd</Data>
    <Data>0001613f</Data>
    <Data>80c</Data>
    <Data>01cfaba71928bf82</Data>
    <Data>C:\Windows\SysWOW64\BMAsia\BMAsia Media Player.exe</Data>
    <Data>C:\Windows\syswow64\USER32.dll</Data>
    <Data>0d1d4bbd-1a85-11e4-b3bf-00a0c6db3a93</Data>
  </EventData>
</Event>
Please help to solve this error.

We can't debug Waveout and WaveoutBuffer class because muliple thread execution at a time.
Aug 5 at 11:53 AM
Hi Mark,

I thing the problem might be Waveoutbuffer.cs class .But I am not sure.
  private void WriteToWaveOut()
        {
            try
            {
                MmResult result;

                lock (waveOutLock)
                {
                    result = WaveInterop.waveOutWrite(hWaveOut, header, Marshal.SizeOf(header));
                }
              
                if (result != MmResult.NoError)
                {
                    throw new MmException(result, "waveOutWrite");
                    //GC.KeepAlive(this);
                }

                GC.KeepAlive(this);
            }
            catch (Exception ex) { obj_Global.WriteErrorLogFile("WaveOutBuffer", "WriteToWaveOut", ex.Message); }
        }
result = WaveInterop.waveOutWrite(hWaveOut, header, Marshal.SizeOf(header)) here access violation occure.But it not come immediately.Please suggest why I do?
Coordinator
Aug 6 at 10:02 AM
This is probably related to the garbage collector moving something that shouldn't be moved. Or a callback message getting processed after a waveOut instance has been closed. You said you got the same issue with DirectSoundOut? That doesn't involve waveOutWrite so I would expect that to be safer?