After searching for all possible sources of information, I managed to find it, I came up with the following solution and thought that it could benefit others in the future:
public class Player extends VideoView implements OnPreparedListener, OnCompletionListener, OnErrorListener { private MediaPlayer mediaPlayer; public Player(Context context, AttributeSet attributes) { super(context, attributes); this.setOnPreparedListener(this); this.setOnCompletionListener(this); this.setOnErrorListener(this); } @Override public void onPrepared(MediaPlayer mediaPlayer) { this.mediaPlayer = mediaPlayer; } @Override public boolean onError(MediaPlayer mediaPlayer, int what, int extra) { ... } @Override public void onCompletion(MediaPlayer mediaPlayer) { ... } public void mute() { this.setVolume(0); } public void unmute() { this.setVolume(100); } private void setVolume(int amount) { final int max = 100; final double numerator = max - amount > 0 ? Math.log(max - amount) : 0; final float volume = (float) (1 - (numerator / Math.log(max))); this.mediaPlayer.setVolume(volume, volume); } }
It seems to work well for me, acting just like a VideoView with the mute / unmute function.
This allows you to make the setVolume method publicly available so that the volume can be controlled outside the scope of the class, but I just needed to turn off the sound / enable the sound.
source share