问题
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