且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

供应选项用户带或不带音频播放视频

更新时间:2022-03-18 02:08:19

使用的AudioManager服务静音或取消静音只与您的视频流。从方式(S)已宣布响应用户触摸事件,就像调用方法:

Use the AudioManager service to mute and unmute just the stream related to your video. From the method(s) you have declared to respond to the user touch events, call methods like:

public void mute() {
  AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
  am.setStreamMute(AudioManager.STREAM_MUSIC, true);
}

public void unmute() {
  AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
  am.setStreamMute(AudioManager.STREAM_MUSIC, false);
}

这将使其他流(通知,报警等)活动的,所以你不能沉默,整个设备只是视频静音。

This will leave the other streams (notification, alarm, etc.) active so you aren't silencing the whole device just to mute the video.

另外,如果你需要建议你的活动而流应该推动音频通过您可以拨打 Activity.setVolumeControlStream(AudioManager.STREAM_MUSIC)来配合你的活动的窗口,该流。

Also, if you need to suggest to your Activity which stream it should be pushing the audio through you can call Activity.setVolumeControlStream(AudioManager.STREAM_MUSIC) to tie your Activity's window to that stream.