Search code examples
androidmedia-player

MediaPlayer is not playing?


when the sound playback is repeated for a long time. when the example is clicked 10 times He does not play. what is the reason why it plays when you restart the application

mediaPlayer = MediaPlayer.create(mContext, R.raw.click);
            mediaPlayer.setVolume(7f, 7f);
            mediaPlayer.start();

Solution

  • mediaPlayer.reset() will help you!

    Ex:

    public static void startSound(Context context, int soundResId) {
        if (mMediaPlayer != null) {
            mMediaPlayer.reset();
            mMediaPlayer = null;
        }
        mMediaPlayer = MediaPlayer.create(context, soundResId);
        mMediaPlayer.start();
    }