Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Muting a video in a VideoView

I'm playing a video (from youtube) using a VideoView, like this:

VideoView video = (ViewView) this.findViewById(R.id.youtube_video);
MediaController controllers = new MediaController(this);
controllers.setAnchorView(video);
video.setMediaController(controllers);

video.setVideoURI(videoUri);
video.start()

I would like to be able to mute the video, but so far the only thing I found is:

AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);

Which works fine in that the video is muted, but the problem is that all of the streamed music is muted, and if there's another video (or audio) which I want to play it's also muted.

Is there a way to just target the specific stream to be muted?
Thanks.

like image 364
Nitzan Tomer Avatar asked Nov 15 '12 09:11

Nitzan Tomer


People also ask

Can you mute a section of a video?

👉 To mute a section of a video: Double-tap on your video: a shortcut menu will appear > tap Split. Now move the playhead to the point where you want to end muting > double-tap on your video > tap Split. Double-tap on the fragment you created > tap Mute from the shortcut menu.

How do I mute VideoView?

If you want to get access to the MediaPlayer of a VideoView you have to call MediaPlayer. OnPreparedListener and MediaPlayer. OnCompletionListener , then you can call MediaPlayer. setVolume(0f, 0f); function to set the volume to 0.


1 Answers

If you are coding in kotlin, Just use this line of code

videoView.setOnPreparedListener { video->
            video.setVolume(0f,0f)
        }
like image 183
Khaled Saifullah Avatar answered Sep 19 '22 13:09

Khaled Saifullah