MediaPlayer的只是在调试模式下播放音乐文件(安卓)音乐文件、只是在、模式下、MediaPlayer

2023-09-07 11:34:54 作者:Extrême(偏激)

我写了一个Android应用程序(在Eclipse),可播放的音乐文件,如下所示:

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?

感谢。

推荐答案

把前一个日志mediaPlayer.setDataSource(文件名)和检查,如果你得到一个有效的文件名在释放模式。

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