简体   繁体   中英

Beginning of sound playback is cut off

I am trying to play back a WAV from an embedded resource but it is consistently chopping off anywhere from 0.5 to 2.0 seconds off the beginning. That is, if the WAV is a recorded voice saying "Hello everybody. Today's news..." then the playback typically cuts off "Hello every---" from the start.

The playback code is pretty simple:

using System.Media;

play(GetResourceStream(audioItem));

...

private static void play(UnmanagedMemoryStream sndData)
{
   SoundPlayer sp = new SoundPlayer(sndData);
   sp.LoadCompleted += delegate( object sender, System.ComponentModel.AsyncCompletedEventArgs e)
   {
      sp.Play();
   };    
   sp.LoadAsync();
}

The original code just created the SoundPlayer object then called the Play() method. I added the LoadAsync() call and LoadCompleted event handler to see if that fixed the problem but it doesn't seem to behave any differently.

Additional information: It appears that sound playback is only chopped off the very first time the app calls SoundPlayer.Play() . Subsequent calls seem to work OK.

I've just had the same problem. The beginning of the sound is cut both in app and when played via an external media player (like VLC). In my case, the issue was related to Bluetooth speakers. After switching the sound output to the wired speakers, it worked fine.

There shouldn't be a problem. Try to put the wav to a file and play from file. If the problem still occurs, I think you should check your sound card's settings for various effects, such as fade.

Try to play "C:\Windows\Media\chord.wav", it's very short, even less then a second.

System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Windows\Media\chord.wav");
player.Play();

If you have no problem with "synchronous" playing, just try SoundPlayer.PlaySync() method. That worked well for me in the exact same case (ie with "embedded resource"s).

my problem was indeed the bluetooth speakers...i disconnected then reconnected and it worked fine after that. I didn't have to switch to wired speakers.

the problem was happening on two different microsoft players AND VLC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM