Following problem: I just want to play a small .wav
file with a mediaplayer in Android. The .wav
file is in the raw
directory. I want to start the sound from the MainActivity. This is how I play the sound:
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.sound1);
mp.start();
As soon as I call mp.start()
I get following errorsin my LogCat:
01-05 11:07:17.729 19960-19960/com.example.simplesound E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
01-05 11:07:17.729 19960-19960/com.example.simplesound E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
01-05 11:07:17.862 19960-19960/com.example.simplesound D/MediaPlayer: setSubtitleAnchor in MediaPlayer
01-05 11:07:17.925 19960-21184/com.example.simplesound E/MediaPlayer: error (1, -2147483648)
01-05 11:07:17.926 19960-19960/com.example.simplesound E/MediaPlayer: Error (1,-2147483648)
Anyone knows how tho fix that?
One of the most important components of the media framework is the MediaPlayer class. An object of this class can fetch, decode, and play both audio and video with minimal setup.
This example demonstrates how do I play background music in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
MediaPlayer player = MediaPlayer.create(this, R.raw.zindgivalaaop);
player.setVolume(50,50);
player.start();
@Override
public void onDestroy() {
super.onDestroy();
player.stop();
player.release();
}
try passing class context instead getApplicationContext()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With