MediaPlayer plays the music files only in debug mode ( Android )

别等时光非礼了梦想. 提交于 2019-12-10 17:17:41

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/9257404/mediaplayer-plays-the-music-files-only-in-debug-mode-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!