静音通过VideoView在Android应用程序正在播放的影像静音、正在播放、应用程序、影像

2023-09-06 03:18:40 作者:无可奈何〆花落去

我想要静音在我的Andr​​oid应用程序正在播放的视频由VideoView。 我找不到任何方法这样做VideoView类。 任何想法如何做到这一点?

我已经发现的MediaPlayer类的方法setVolume,但我无法找到任何工作code。通过类的MediaPlayer播放视频。 所以我相信我可以用这种方法来设置音量0。

所以我在寻找任何工作code播放视频使用的MediaPlayer类或如何使用VideoView类控制音量。

下面是code使用VideoView,而我使用的播放视频。

  @覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_video);

    VideoView videoView =(VideoView)this.findViewById(R.id.VVSimpleVideo);
    的MediaController MC =新的MediaController(本);
    mc.setAnchorView(videoView);
    mc.setMediaPlayer(videoView);
    videoView.setMediaController(MC);
    字符串_path =/mnt/sdcard/Movies/video5.mp4;

    videoView.setVideoPath(_path);

    videoView.requestFocus();
    videoView.start();


}
 

解决方案

我已经做到了这一点使用的MediaPlayer类。 我已经使用的MediaPlayer类的setVolume功能,将音量设置为0。 还我已认识到,不使用AudioManager类,因为使用AudioManager如果一组体积为0,然后将其设置体积为0的MediaPlayer和VideoView的所有实例。但是,如果你将使用setVolume()则会MediaPlayer的方法,然后它只是静音该实例的体积只有

另外设置音量为0是机器人容易使用VideoView因为VideoView是包装过的MediaPlayer类,并只允许访问的MediaPlayer的一些功能。 我也看过一些博客,虽然你可以使用VideoView实例引用的MediaPlayer实例,但它非常复杂,它不建议这样做。 希望这将是如何尽量做类似的事情有帮助的其他新的读者。

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?

Android开发学习 VideoView播放视频

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.

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

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


}

解决方案

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.

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.