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.
👉 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.
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.
If you are coding in kotlin, Just use this line of code
videoView.setOnPreparedListener { video->
video.setVolume(0f,0f)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With