MediaPlayer 仅在调试模式下播放音乐文件(Android)

发布于 2025-01-04 18:53:37 字数 489 浏览 5 评论 0原文

我编写了一个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 技术交流群。

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

发布评论

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

评论(2

守不住的情 2025-01-11 18:53:37

在“mediaPlayer.setDataSource(fileName)”之前放置一个日志,并检查您是否在发布模式下获取有效的文件名。

Put a log before "mediaPlayer.setDataSource(fileName)" and check if you are getting a valid fileName in release mode.

注定孤独终老 2025-01-11 18:53:37

我有类似的问题,就我而言,它不喜欢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.

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