MediaPlayer plays music files in debug mode only (Android)

I wrote 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. Could you help me find out what happened?

Thanks.

+4
source share
1 answer

Put the log in front of "mediaPlayer.setDataSource (file_name)" and check if you get a valid file name in release mode.

0
source

Source: https://habr.com/ru/post/1396150/


All Articles