I want to mute a playing Video by VideoView in my Android Application. I couldn't find any method to do so in VideoView Class. Any idea how to do this?
I have found a method "setVolume" in MediaPlayer Class, But I am unable to find any working code to play video by MediaPlayer class. So I believe I can set volume 0 by this method.
Therefore I am looking for any working code to play video using MediaPlayer Class or how to control volume using VideoView Class.
Below is the code for playing video using VideoView , which I am using.
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); VideoView videoView = (VideoView)this.findViewById(R.id.VVSimpleVideo); MediaController mc = new MediaController(this); mc.setAnchorView(videoView); mc.setMediaPlayer(videoView); videoView.setMediaController(mc); String _path = "/mnt/sdcard/Movies/video5.mp4"; videoView.setVideoPath(_path); videoView.requestFocus(); videoView.start(); }
Swipe right or left to find the video clip you would like to change the audio options for. 3. Tap on the 3 dots below the video clip and tap on “Mute” or “Unmute” in the dropdown 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.
Do this:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); VideoView videoView = (VideoView)this.findViewById(R.id.VVSimpleVideo); MediaController mc = new MediaController(this); mc.setAnchorView(videoView); mc.setMediaPlayer(videoView); videoView.setMediaController(mc); String _path = "/mnt/sdcard/Movies/video5.mp4"; videoView.setVideoPath(_path); videoView.setOnPreparedListener(PreparedListener); videoView.requestFocus(); //Dont start your video here //videoView.start(); } MediaPlayer.OnPreparedListener PreparedListener = new MediaPlayer.OnPreparedListener(){ @Override public void onPrepared(MediaPlayer m) { try { if (m.isPlaying()) { m.stop(); m.release(); m = new MediaPlayer(); } m.setVolume(0f, 0f); m.setLooping(false); m.start(); } catch (Exception e) { e.printStackTrace(); } } };
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