java 在 Android 中播放 Ogg Sound

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11093238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 03:44:20  来源:igfitidea点击:

Playing Ogg Sound in Android

javaandroidmedia-playerplaybackogg

提问by Erol

In my application, I am trying to play a sound file in ogg format, stored in raw folder in res directory of my application. When I press the button that calls below function, it just freezes with the button pressed and does not respond. In the end, I have to terminate the application from Eclipse. Nothing about an error or exception in Logcat.

在我的应用程序中,我试图播放 ogg 格式的声音文件,该文件存储在我的应用程序 res 目录中的 raw 文件夹中。当我按下调用下面函数的按钮时,它只是在按下按钮时冻结并且没有响应。最后,我必须从 Eclipse 终止应用程序。Logcat 中没有关于错误或异常的信息。

In debugging mode, it enters create function and never comes back. What am I doing wrong?

在调试模式下,它进入创建功能,永远不会回来。我究竟做错了什么?

    private void playbeep()
{
    mPlayer = MediaPlayer.create(this, R.raw.beep);
    mPlayer.start();
    mPlayer.release();
}

回答by Kurty

You start and release the MediaPlayer at the same time. Try taking this out and see if it works.

您同时启动和释放 MediaPlayer。尝试取出它,看看它是否有效。

mPlayer.release();

Also, check my post hereto make sure you have the MediaPlayer set up correctly. If all else fails, try your audio file in a different format.

此外,检查我的岗位在这里,以确保您有MediaPlayer的设置正确。如果所有其他方法都失败了,请尝试使用其他格式的音频文件。