gpt4 book ai didi

C#4.0 使用 winmm.dll 以超过 192kbps 的速度播放 .mp3 文件时出现问题

转载 作者:太空狗 更新时间:2023-10-30 00:51:30 29 4
gpt4 key购买 nike

MCIERR_INTERNALI 正在尝试在应用程序中制作一个简单的媒体播放器,但我注意到我的代码将不会播放音乐,除非文件是大约 192kbps 或更低的低比特率。问题是我的大部分音乐都在 260-320kbps 左右。

这是我的代码,如果我可以做些什么来提高“可用”比特率选项,请告诉我,否则我需要一个新的 DLL 建议!

class MusicPlayer
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);

private static void checkMCIResult(long code)
{
int err = (int)(code & 0xffffffff);
if (err != 0)
{
throw new Exception(string.Format("MCI error {0}", err));
}
}

public void open(string file)
{
string command = "open \"" + file + "\" type MPEGVideo alias MyMp3";
checkMCIResult(mciSendString(command, null, 0, 0));
}

public void play()
{
string command = "play MyMp3";
mciSendString(command, null, 0, 0);
}
public void pause()
{
string command = "stop MyMp3";
mciSendString(command, null, 0, 0);
}
}

**编辑:-Winform应用

-使用 Windows 7 sp1

-使用 Visual Studio 2013 社区版

-从错误捕获我现在看到错误号是 289,-256 = 22: MCIERR_INTERNAL,不知道那是什么

最佳答案

这不是 Windows 的固有限制,像这样的问题是环境问题。基本 list :

  • known-good MP3 file 试试这个.该测试文件以 320 kbps 编码。这有助于消除文件的特​​定问题,例如只允许在经过批准的播放器上播放的不稳定的 DRM 方案。
  • 确保在 STA 线程上运行此代码,这种线程由 Winforms 或 WPF 应用程序提供。 不是控制台模式应用程序,它需要您在 this post 中找到的那种代码.
  • 注意不要安装非标准的 ACM 驱动程序。那里有很多 垃圾,总是以强烈的不信任对待“编解码器包”。查看 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32 注册表项,这是注册 ACM 驱动程序的地方。
  • 最后但并非最不重要的一点是,只要您忽略 mciSendString() 的返回值,您就是瞎子。当它失败时,它会生成一个错误代码,告诉您原因。

错误检查器方法的简单实现:

    private static void checkMCIResult(long code) {
int err = (int)(code & 0xffffffff);
if (err != 0) {
throw new Exception(string.Format("MCI error {0}", err));
}
}

用法:

    public static void open(string file) {
string command = "open \"" + file + "\" type MPEGVideo alias MyMp3";
checkMCIResult(mciSendString(command, null, 0, 0));
}

有很多可能的 MCI 错误,您会在计算机上的 Windows SDK“include”目录中的 MMSystem.h 文件中找到它们。比如 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\MMSystem.h。从 MCIERR_INVALID_DEVICE_ID 开始,从错误代码中减去 256。顺便提一下你的 Windows 和 VS 版本。

关于C#4.0 使用 winmm.dll 以超过 192kbps 的速度播放 .mp3 文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26983847/

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