android MediaPlayer not playing mp3 file

吃可爱长大的小学妹 提交于 2019-11-30 06:56:23

The problem is that the media volume is set to 0 (not the ringer volume). You can set it by:

AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);

Have a a look at the developer page and another question for the explanation of parameters for setStreamVolume(int, int, int).

Try replacing these two lines:

MediaPlayer mp = new MediaPlayer();
mp.create(getApplicationContext(), R.raw.norm_iphone_money);

with this one line:

MediaPlayer mp = MediaPlayer.create(this, R.raw.norm_iphone_money);

And see if that works.

The problem is with emulator, change the emulator or try to run the application on a real device. This should solve the problem.

The static method create(Context, int) from the type MediaPlayer should be accessed in a static way. Try this:

MediaPlayer.create(getApplicationContext(), R.raw.norm_iphone_money).start();

It will play the .mp3 with this line too

mp.create(getApplicationContext(), R.raw.norm_iphone_money).start();
Guzhov

I would suggest this :

MediaPlayer mp = new MediaPlayer();
//bla bla bla
mp = MediaPlayer.create(getApplicationContext(), R.raw.norm_iphone_money);
user3467150

Had the same problem after i clicked to start the Media Player, the screen went black and the app stopped.

i just changed

MediaPlayer mp = MediaPLayer.create(this,R.raw.sound); mp.start();

to

MediaPlayer mp = MediaPLayer.create(this,R.raw.sound).start();

I am not really sure what is the difference there, but it solved my problem.

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