MediaPlayer 仅在调试模式下播放音乐文件(Android)
我编写了一个Android应用程序(在eclipse中),它播放音乐文件如下:
MediaPlayer mediaPlayer = new MediaPlayer();
try
{
mediaPlayer.setDataSource(fileName);
mediaPlayer.prepare();
mediaPlayer.start();
// mediaPlayer.stop();
}
catch (Exception e)
{
Log.d("Exception---", e.getMessage());
}
当我运行它时,它不播放文件(并且不显示任何异常),但是当我切换到“调试模式”并跟踪时它逐行播放文件。我真的很困惑。您能帮我找出问题所在吗?
谢谢。
I have written an Android application ( in eclipse) that plays a music file as follows:
MediaPlayer mediaPlayer = new MediaPlayer();
try
{
mediaPlayer.setDataSource(fileName);
mediaPlayer.prepare();
mediaPlayer.start();
// mediaPlayer.stop();
}
catch (Exception e)
{
Log.d("Exception---", e.getMessage());
}
When I run it, it does not play the file ( and does not show any exception ), but when I switch to 'debug mode', and trace it line by line, it plays the file. I'm really confused. Would you please help me find out what's wrong?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在“mediaPlayer.setDataSource(fileName)”之前放置一个日志,并检查您是否在发布模式下获取有效的文件名。
Put a log before "mediaPlayer.setDataSource(fileName)" and check if you are getting a valid fileName in release mode.
我有类似的问题,就我而言,它不喜欢player.PrepareAsync()命令。除了输出窗口中的一些微小信息没有任何帮助之外,它在调试器中没有给出任何错误。意识到有什么东西绊倒了玩家,我开始改变一些东西,并将player.prepareAsync更改为player.Prepare(),这就是Xamarin中所做的一切。
I had similar problem and in my case it didn't like the player.PrepareAsync() command. It wasn't giving any errors in debugger except some miniscule info in the output window which wasn't of any help. Realizing that something was tripping the player I started to change a few things and changed the player.prepareAsync to player.Prepare() and thats all it took in Xamarin.