WAV 从文件播放,不直接从 URL 播放

发布于 2024-12-06 23:44:41 字数 670 浏览 4 评论 0原文

我有一个返回 8 位 PCM、单声道、8 kHz WAV 声音的 URL。当我尝试通过 Android 的 MediaPlayer 类播放该 URL 时,我在 LogCat 中收到错误和以下内容:

09-29 17:36:40.710: ERROR/PlayerDriver(562): Command PLAYER_INIT completed with an error or info PVMFFailure
09-29 17:36:40.730: ERROR/MediaPlayer(25215): error (1, -1)

URL 返回的内容类型是 audio/x-wav。 I 调用prepareAsync()后发生错误:

String uri = "http://whatever";
s_Player.setDataSource(uri);
s_Player.setAudioStreamType(AudioManager.STREAM_MUSIC);
s_Player.prepareAsync();

当我将uri替换为文件系统中存储的相同声音的文件路径时,它播放正常。在 Android 浏览器中播放 URL 即可。所以一定是我误用了 MediaPlayer。有什么想法吗?

编辑:它位于模拟器上(目前),因此权限不是问题。

I have a URL that returns a 8-bit PCM, mono, 8 kHz WAV sound. When I try to play that URL via Android's MediaPlayer class, I get an error and the following in LogCat:

09-29 17:36:40.710: ERROR/PlayerDriver(562): Command PLAYER_INIT completed with an error or info PVMFFailure
09-29 17:36:40.730: ERROR/MediaPlayer(25215): error (1, -1)

The content type that the URL returns is audio/x-wav. I The error occurs after calling prepareAsync():

String uri = "http://whatever";
s_Player.setDataSource(uri);
s_Player.setAudioStreamType(AudioManager.STREAM_MUSIC);
s_Player.prepareAsync();

When I replace uri with a file path to the same sound stored in the filesystem, it plays fine. Playing the URL in the Android browser works. So it must be me somehow misusing MediaPlayer. Any ideas, please?

EDIT: it's on the emulator (for now), so permissions are not an issue.

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

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

发布评论

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

评论(1

柒七 2024-12-13 23:44:41

也许您没有在清单中请求互联网许可???

Maybe you didn't request Internet permission in the manifest???

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