Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: WasapiOut exclusive mode problem

$
0
0
Hi!

My goal is to play wave file in exclusive mode. I think. I just don't want any other application to interrupt my wave.
From discussions in the past on this project I noticed sample rate, channels and format may be important. My wave is 22050 hz, 2 channels and IeeeFloat format.

This is a part of my code:
        waveOut = new WasapiOut(AudioClientShareMode.Exclusive, false, 300);
(...)
        private void OnWaveOutPlaybackStopped(object sender, NAudio.Wave.StoppedEventArgs e)
        {
            log.Debug("Odtwarzanie pliku wav zakończone");

            waveOut.Stop();
            waveStream.Close();
            waveStream.Dispose();
            waveReader.Close();
            waveReader.Dispose();
        }

        private void PlayVoiceMessage()
        {
            if (File.Exists(m_waveFile))
            {
                try
                {
                    waveReader = new WaveFileReader(m_waveFile);
                    waveStream = new WaveChannel32(waveReader);
                    string strFormat = waveStream.WaveFormat.ToString();
                    string strSampleRate = waveStream.WaveFormat.SampleRate.ToString();
                    string strChannels = waveStream.WaveFormat.Channels.ToString();
                    waveOut.PlaybackStopped += new EventHandler<NAudio.Wave.StoppedEventArgs>(OnWaveOutPlaybackStopped);
                    waveOut.Init(waveStream);
                    waveOut.Play();
                    
                    log.Info("Odtwarzanie pliku wav rozpoczęte");
                }
                catch (Exception e)
                {
                    string sMsg = String.Format("Błąd odtwarzania! w {0}. Przyczyna: {1}.\nŚcieżka {2}", e.Source, e.Message, e.StackTrace);
                    log.Error(sMsg);
                }
            }
            else
            {
                log.Error("Plik Wav nie istnieje");
            }
        }
My code catch the exception in the "waveOut.Init(waveStream);" line.
The error message is: Can't find a supported format to use.

What kind of problem is with this file?

Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>