King Rool
King Rool

Reputation: 17

I can't get the mediaplayer working in android studio

I'm trying to get some sound in my app, but I can't get the mediaplayer working! I got some errors like:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference

with the following code:

private MediaPlayer mPlayer;

@Override
protected void onCreate(Bundle savedInstanceState) {
mPlayer = MediaPlayer.create(this, R.raw.NAMEOFSOUND);
}

protected void playBtnClicked(){
    mPlayer.start();
}

It just doesn't work, whatever I do ... Does someone got some tips/Can someone help me out? The ''NAMEOFSOUND'' is a .mp3 file, I don't know if it even matters? Thank you!

SOLVED: I just solved it by coverting the file with a converter. Just changing the name+.mp3 didn't solve it; NullPointerException in Java Android App MediaPlayer , comment of Berty did the trick!

Upvotes: 0

Views: 788

Answers (1)

Daniele
Daniele

Reputation: 4343

As you can see in the supported Media formats .mav is not supported by android. you should convert it to mp3 or any of the supported file formats

Upvotes: 1

Related Questions