gpt4 book ai didi

c# - 为什么在调试条件下无法播放DirectSound Buffer?

转载 作者:行者123 更新时间:2023-12-02 23:00:43 26 4
gpt4 key购买 nike

我的wave无法在调试下播放。如果按CTRL + F5,则会得到一个不错的WAV,并且控制台会写出文件光标位置(buf.PlayPosition),然后在声音结束时退出该方法。在调试下(当我刚按F5时)没有音频输出,但是在控制台窗口中文件光标的位置仍然增加,并且该方法无一异常(exception)地退出。

using Microsoft.DirectX.DirectSound;

public void Play()
{
var fileName = "bass.wav";
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
using (var dev = new Device())
{
dev.SetCooperativeLevel(this, CooperativeLevel.Priority);
using (Buffer buf = new Buffer(stream, dev))
{
buf.Volume = 0;
buf.Play(0, BufferPlayFlags.Default);
while (buf.Status.Playing)
{
System.Console.WriteLine("playing " + buf.PlayPosition);
}
}
}
}
}

有任何想法吗?

最佳答案

也许您需要使用BufferDescription给缓冲区“Global Focus”。从C++文档中:

"The DSBCAPS_GLOBALFOCUS flag in the example ensures that the buffer will continue playing even when the application window is not in the foreground. Without this flag, the buffer will be muted when another application or even a dialog box has the input focus."



尝试使用构造函数的 public SecondaryBuffer(Stream, BufferDescription, Device); 形式。

关于c# - 为什么在调试条件下无法播放DirectSound Buffer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2135342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com