'Mute audio on ExoPlayer
I'm using Google new MediaPlayer named ExoPlayer and cannot find a way to mute the sound
Is there an easy way to mute audio track on Google ExoPlayer ? Or changing volume ?
Solution 1:[1]
The new way to mute and unmute volume as of version 2.X.X done as follows:
int currentvolume = player.getVolume();
make sure to call the line above after starting the player otherwise you will get a nullpointerexception
to mute volume:
player.setVolume(0f);
to unmute volume:
player.setVolume(currentVolume);
Solution 2:[2]
Easily you can do it with ExoPlayer:
Java Code:
float currentVolume = player.getVolume();
if (currentVolume == 0f) {
player.setVolume(1f);
} else {
player.setVolume(0f);
}
Kotlin Code:
val curentVol = player?.volume
if (curentVol == 0f) {
player?.volume = 1f
} else {
player?.volume = 0f
}
Solution 3:[3]
In ExoPlayer 2.x.x:
get the current volume:
int currentVolume = player..getAudioComponent().getVolume();
mute:
player.getAudioComponent().setVolume(0f);
unmute:
player.getAudioComponent().setVolume(currentVolume);
Solution 4:[4]
try
player.setSelectedTrack(DemoPlayer.TYPE_AUDIO, DemoPlayer.TRACK_DISABLED);
analogous to this line of code
Solution 5:[5]
Just simply use player.setVolume(0) will silent the video.
Solution 6:[6]
I will recommend get the current volume first and then mute it. When you will unmute you can give user same volume.
float currentvolume;
currentvolume = player.getVolume();
player.setVolume(0.0f);
Solution 7:[7]
Mute ExoPlayer using Kotlin
player.audioComponent?.volume = 0f
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sambhav. K |
| Solution 2 | Ashav Kothari |
| Solution 3 | Hadi |
| Solution 4 | thomasb |
| Solution 5 | Allen Vork |
| Solution 6 | Asuk Nath |
| Solution 7 | Cube |
