0

I am showing the list of videos using TextureView and MediaPlayer. I want to mute/unmute sound for all videos.

What is the problem

Problem is that when I use notifyDataSetChanged() method then the playing video gets reloaded because onBindViewHolder() executes after notifyDataSetChanged().

Code on mute/unmute icon's click

case R.id.volume_button:
                if (isToPlaySoundInitially) {
                    volumeKey.setImageResource(R.drawable.unmute_video);
                    isToPlaySoundInitially = false;
                    mVideoView.unMuteVideo();

                } else {
                    volumeKey.setImageResource(R.drawable.mute_video);
                    isToPlaySoundInitially = true;
                    mVideoView.muteVideo();

                }
                notifyDataSetChanged();
                break;

Method to mute/unmute sound

public void muteVideo() {
    if (this.mp != null) {
        mp.setVolume(0, 0);
    }
}

public void unMuteVideo() {
    if (this.mp != null) {
        mp.setVolume(1, 1);
    }
}

Please suggest how can I mute/unmute sound for all items of the list.

Thank You.

Ashish Tiwari
  • 2,168
  • 4
  • 30
  • 54

1 Answers1

0

Use setVolume function of MediaPlayer class to set the volume to 0. Do not use AudioManager class, because using AudioManager if you set volume to 0, then it set volume to 0 for all the instance of MediaPlayer and VideoView.

But if you will use setVolume() method of MediaPlayer then it will just Mute the volume of that instance only.

Also set volume to 0 is not easy using VideoView because VideoView is a wrapper over MediaPlayer class and just allow to access few function of MediaPlayer.

Saurav Prakash
  • 588
  • 1
  • 5
  • 26
  • I think this is not my problem. I don't have any issue to mute and unmute particular video. I want to mute sound for all videos when I mute any one video, same for unmute. You can check Facebook application if you have any doubt. – Ashish Tiwari Apr 25 '17 at 08:16
  • i hope this might help you :http://stackoverflow.com/a/10896086/7795876 – Saurav Prakash Apr 25 '17 at 09:05