I know that there is some similar questions, but none of them answered my question. When I Click a button, media player is called, and this is appearing in the log.
06-02 00:20:38.980 26035-26035/myapp.com.facadezpontos E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
06-02 00:20:39.019 26035-26035/myapp.com.facadezpontos E/MediaPlayer: Should have subtitle controller already set
06-02 00:20:39.026 26035-26035/myapp.com.facadezpontos E/MediaPlayer: Should have subtitle controller already set
After some time, this message above is substituted by this bellow, and the sound provided by the media player does not play anymore.
06-02 00:23:21.032 28749-28749/myapp.com.facadezpontos E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
06-02 00:23:21.076 28749-28749/myapp.com.facadezpontos E/MediaPlayer: Should have subtitle controller already set
06-02 00:23:21.090 28749-28749/myapp.com.facadezpontos E/MediaPlayer: Should have subtitle controller already set
06-02 00:23:21.396 28749-28772/myapp.com.facadezpontos E/MediaPlayer: error (1, -19)
06-02 00:23:21.396 28749-28749/myapp.com.facadezpontos E/MediaPlayer: Error (1,-19)
this is the code for the MediaPlayer
public void buttonClick(Context context, MediaPlayer mp){
mp = MediaPlayer.create(context, R.raw.bubble_nice);
mp.start();
}
I solved the problem!
I changed the way I call the sound file, here's how I did it.
I put the file inside the assets in order to make it works.
if(mp.isPlaying())
{
mp.stop();
}
try {
mp.reset();
AssetFileDescriptor afd;
afd = getAssets().openFd("AudioFile.mp3");
mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
mp.prepare();
mp.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I got this from here: android - how to make a button click play a sound file every time it been pressed?