简体   繁体   English

声音播放的开始被切断

[英]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.我正在尝试从嵌入式资源播放 WAV,但它始终会在开始时从 0.5 秒到 2.0 秒的任何时间切断。 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.也就是说,如果 WAV 是录制的声音,说“大家好。今天的新闻……”,那么播放通常会从一开始就切断“大家好——”。

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.原始代码只是创建了SoundPlayer对象,然后调用了Play()方法。 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.我添加了LoadAsync()调用和LoadCompleted事件处理程序,以查看是否解决了问题,但它的行为似乎没有任何不同。

Additional information: It appears that sound playback is only chopped off the very first time the app calls SoundPlayer.Play() .附加信息:声音播放似乎只在应用程序第一次调用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).在应用程序中和通过外部媒体播放器(如 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.尝试将 wav 放入文件并从文件中播放。 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.尝试播放“C:\Windows\Media\chord.wav”,它很短,甚至不到一秒。

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.如果您对“同步”播放没有问题,只需尝试SoundPlayer.PlaySync()方法。 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.问题发生在两个不同的微软播放器和 VLC 上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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