Android Mediaplayer Not Playing Mp3 File
I have written the most basic application I can think of to try to play an mp3 file, but it is not working. I don't get any errors, but when the application starts up, the sound i
Solution 1:
The problem is that the media volume is set to 0 (not the ringer volume). You can set it by:
AudioManageraudioManager= (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
Have a look at the developer page and another question for the explanation of parameters for setStreamVolume(int, int, int).
Solution 2:
Try replacing these two lines:
MediaPlayermp=newMediaPlayer();
mp.create(getApplicationContext(), R.raw.norm_iphone_money);
with this one line:
MediaPlayermp= MediaPlayer.create(this, R.raw.norm_iphone_money);
And see if that works.
Solution 3:
The problem is with emulator, change the emulator or try to run the application on a real device. This should solve the problem.
Solution 4:
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();
Solution 5:
I would suggest this :
MediaPlayermp=newMediaPlayer();
//bla bla bla
mp = MediaPlayer.create(getApplicationContext(), R.raw.norm_iphone_money);
Post a Comment for "Android Mediaplayer Not Playing Mp3 File"