Sounds muted on some phones

I am a Soundboard application developer. Many users told me that in their phones some of the sounds were cut off earlier. I have a Nexus One and HTC Tattoo, and everything works fine, I never noticed that it was turned off on my phones.

This is my code for the audio part:

Firstly, I have a MediaPlayer object in my main class:

private MediaPlayer mp = null;

And when I click the button, this is the code:

    private OnClickListener onClickSound = new OnClickListener() {

    public void onClick(View v) {
        if(mp != null){
            mp.stop();
            mp.release();
            mp = null;
        }

        mp = MediaPlayer.create(getBaseContext(), mp3id));
        mp.start();
        mp.setOnCompletionListener(completionListener);
    }
};

And this will be finalListener:

    MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener(){

    public void onCompletion(MediaPlayer mediaP) {
        if(mp != null && !mp.isPlaying()){
            mp.stop();
            mp.release();
            mp = null;
        }
    }

};

Do you have any clues?

Hi

+3
source share
1 answer

You start playing before the player loads all the media. Use setOnPreparedListener to run only after the player is ready.

+2
source

Source: https://habr.com/ru/post/1763486/


All Articles