我想要静音视频,并使用Videoview播放视频
_player.setVideoURI("/sdcard/Movie/byern.mp4");
_player.start();
现在,如何解决它?
答案 0 :(得分:1)
您需要调用想要使用 VideoView 的 MediaPlayer.OnPreparedListener 和 MediaPlayer.OnCompletionListener 。然后您可以调用 setVolume 方法public使得卷可以在类的范围之外进行控制。下面3将解决这些问题。
答案 1 :(得分:0)
您可以像这样自定义 VideoView
public class VideoPlayer extends VideoView implements OnPreparedListener, OnCompletionListener, OnErrorListener {
private MediaPlayer mediaPlayer;
public Player(Context context, AttributeSet attributes) {
super(context, attributes);
//init player
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;//change 100 to zeo
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);
}
}