2

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();
    }
  • Possible duplicate of [Why MediaPlayer throws NOT present error when creating instance of it?](https://stackoverflow.com/questions/24501086/why-mediaplayer-throws-not-present-error-when-creating-instance-of-it) – Isaac Jun 02 '17 at 03:37
  • this question does not solve the problem –  Jun 02 '17 at 04:01
  • 1
    @Felipe Have you solved this issue ? – Sagar Feb 23 '18 at 10:23
  • @SagarHudge yes, I posted the answer bellow. I hope it helps you too –  Feb 24 '18 at 20:35

1 Answers1

2

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?