Reputation: 31
I had to mute the volume of video when an audio is playing in the background(in my same app). But when I try to set the volume of the mediaplayer in the videoview.onPrepared callback, it is not having any effect on muting the video.
//muteVolume is a boolean that is true if a background audio is playing, otherwise false
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
@Override
public void onPrepared(MediaPlayer mediaPlayer)
{
float volumeValue = ((muteVolume) ? 0.f : 1.f);
mediaPlayer.setVolume(volumeValue,volumeValue);
videoView.setZOrderOnTop(false);
videoView.start();
}
});
This works on the Samsung GT tablet whereas it does not work on some android devices.
I cant set the volume of the stream in my app, because in my app itself, I need to play an audio in the background with full volume.
There are also some apps(Vplayer) which are able to mute the video in the same device in which the above code is not working
Is there any other way to set the volume of the video such that the video is muted and another audio plays in the background? Or Am I missing something?
Upvotes: 3
Views: 2903
Reputation: 41
This code will only work if the audio was already playing and the videoView gets prepared (as you are making the change in the onPrepared listener of VideoView). However, from the language of your question it appears you are trying to mute an already playing video when an audio gets invoked in the background (That is, the other way round). If that is the case please create a method for setting the volume to zero, and call the method when the audio starts playing.
PS: Since you are saying its working on Samsung GT Tablet, I feel my observation might not be correct as well. Can you make the question more clear as to when is the requirement arising?
Upvotes: 0
Reputation: 85
i used setVolume(0,0) right after i called start and it muted for me...
Upvotes: 2