Windows Mobile 6.5 SndPlayAsync - C# 包装器?

发布于 2024-10-09 07:22:24 字数 276 浏览 0 评论 0原文

我正在 Windows Mobile 6.5 上实现 mp3 播放。我需要使用 SndPlayAsync API 函数,因为我不想在播放文件之前阻止调用线程(SndPlaySync 会阻止直到音频文件正在播放)。不幸的是,SndPlayAsync 方法采用声音句柄而不是声音文件路径作为参数,因此需要在播放之前打开句柄并在播放后释放它。问题是我在这个 API 中没有任何关于播放完成的信息。有人使用 C# 包装器来实现这个 API 吗?我在哪里可以买到一个?我查过 OPENNETCF 但他们似乎不支持这个 API。

问候

I'm implementing mp3 playback on Windows Mobile 6.5. I need to use SndPlayAsync API function since I don't want to block calling thread until the file is played (SndPlaySync blocks until the audio file is playing). Unfortunately the SndPlayAsync method takes sound handle instead of sound file path as parameter so there's a need to open the handle before and release of it after playback. The problem is that I don't have any information about the playback completion in this API. Did anybody use a C# wrapper for this API? Where can I get one? I've looked up OPENNETCF but they seem not to support this API.

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

亽野灬性zι浪 2024-10-16 07:22:24

您必须先调用 SndOpen 才能获取句柄。查看文档,声明将是这样的:

[DllImport("coredll", SetLastError=true)]
public static extern int SndOpen(string fileName, out IntPtr handle);

[DllImport("coredll", SetLastError=true)]
public static extern int SndPlayAsync (IntPtr handle, int flags);

[DllImport("coredll", SetLastError=true)]
public static extern int SndClose(IntPtr handle);

所以你可以使用类似这样的东西来调用它:

IntPtr handle;
var result = SndOpen("myfile.mp3", out handle);
if(result == 0) SndPlayAsync(handle, 0);

...

SndClose(handle);

You have to call SndOpen first to get the handle. Looking at the docs, the declarations would be something along these lines:

[DllImport("coredll", SetLastError=true)]
public static extern int SndOpen(string fileName, out IntPtr handle);

[DllImport("coredll", SetLastError=true)]
public static extern int SndPlayAsync (IntPtr handle, int flags);

[DllImport("coredll", SetLastError=true)]
public static extern int SndClose(IntPtr handle);

So you'd use something like this to call it:

IntPtr handle;
var result = SndOpen("myfile.mp3", out handle);
if(result == 0) SndPlayAsync(handle, 0);

...

SndClose(handle);
动次打次papapa 2024-10-16 07:22:24

如果您使用 .NET CF,则无需创建包装器,只需使用 System.Media.SoundPlayer 类来处理它。有几个选项,包括 PlaySync,它将同步播放声音。

例如:

string path = "\\Program Files\\SNAP.App.CE\\Content\\5LongLow.wav";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(path);
player.PlaySync();

如果您不想阻塞 UI 线程,也可以将其放在单独的线程中。

If you are using .NET CF there is no reason to create a wrapper, you can just use the System.Media.SoundPlayer class to handle it. There are several options including PlaySync which will play the sound synchronously.

For instance:

string path = "\\Program Files\\SNAP.App.CE\\Content\\5LongLow.wav";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(path);
player.PlaySync();

You can also put it in a separate thread if you don't want to block the UI thread.

你的他你的她 2024-10-16 07:22:24

您可以使用 SndGetWaitHandle 获取将发出信号的事件的句柄当声音播放完毕时。您可以使用 WaitForSingleObject API 来等待或测试事件是否已设置。

You can use SndGetWaitHandle to get a handle to an event which will be signaled when the sound is finished playing. You can use the WaitForSingleObject API to wait or test if the event has been set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文