在 Android 应用程序中通过 VideoView 将正在播放的视频静音 [英] Mute a playing video by VideoView in Android Application

查看:53
本文介绍了在 Android 应用程序中通过 VideoView 将正在播放的视频静音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 Android 应用程序中通过 VideoView 将正在播放的视频静音.我在 VideoView 类中找不到这样做的任何方法.知道如何做到这一点吗?

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?

我在 MediaPlayer 类中找到了一个方法setVolume",但是我找不到任何可以通过 MediaPlayer 类播放视频的工作代码.所以我相信我可以通过这种方法设置音量0.

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.

因此,我正在寻找任何工作代码来使用 MediaPlayer 类播放视频或如何使用 VideoView 类控制音量.

Therefore I am looking for any working code to play video using MediaPlayer Class or how to control volume using VideoView Class.

以下是使用 VideoView 播放视频的代码,我正在使用.

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();


}

推荐答案

我已经使用 MediaPlayer 类完成了这项工作.我已经使用 MediaPlayer 类的 setVolume 函数将音量设置为 0.我也意识到不要使用 AudioManager 类,因为如果使用 AudioManager,如果将音量设置为 0,那么它会将 MediaPlayer 和 VideoView 的所有实例的音量设置为 0.但是,如果您将使用 MediaPlayer 的 setVolume() 方法,那么它只会将该实例的音量静音.

I have done this using MediaPlayer class. I have used setVolume function of MediaPlayer class to set the volume to 0. also I have realised that dont use AudioManager class, because using AudioManager if a set volume to 0, then it set volume to 0 for all the instance of MediaPlayer and VideoView. But if you will use setVolume() method of MediaPlayer then it will just Mute the volume of that instance only.

使用 VideoView 将音量设置为 0 也很容易,因为 VideoView 是 MediaPlayer 类的包装器,只允许访问 MediaPlayer 的一些功能.另外我在一些博客上读到,虽然您可以使用 VideoView 实例引用 MediaPlayer 实例,但它非常复杂,不建议这样做.希望这对其他新读者如何尝试做类似的事情有所帮助.

Also set volume to 0 is bot easy using VideoView because VideoView is a wrapper over MediaPlayer class and just allow to access few function of MediaPlayer. Also I have read on some blog that though you can reference MediaPlayer instance using VideoView instances, but its very complex and its not recommended to do so. Hope this would be helpful to other new readers how try to do similar things.

这篇关于在 Android 应用程序中通过 VideoView 将正在播放的视频静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆