在Android应用中使Webview静音 [英] Mute webview in android apps
问题描述
我正在构建一个包含一些WebViews
的应用.
I'm building an app that includes some WebViews
.
我想忽略其中一个(不是整个应用程序或设备,只是那个特定的WebView
),但是对此问题没有确定的答案.
有谁知道如何在Android中静音WebView
声音?
I want to mute one of them (not the whole app or device just that specific WebView
) I searched but there's no certain answer to this question.
Is there anyone knows how to mute a WebView
sound in Android?
推荐答案
您不能仅静音WebViews卷,但是可以在显示WebView时静音整个系统卷.喜欢 :
当您显示特定的WebView时,请使用以下方法:
You can't mute only WebViews volume, but you can mute the whole system volume when you are showing the WebView. Like :
When you are showing that particular WebView use the below method :
public static void mute(Context context) {
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
int mute_volume = 0;
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mute_volume, 0);
}
当未显示webView时,请设置最大音量,例如:
And when the webView is not shown set max volume Like :
public static void unmute(Context context) {
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
int unmute_volume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, unmute_volume, 0);
}
如果您不想设置完整音量,则可以通过以下方式获取当前系统音量
If you don't want to set full volume you can get current system volume by
mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
并将其保存在本地,然后在退出Webview时再次将其重新设置.
and save it locally and set it back again when you exit the Webview.
这篇关于在Android应用中使Webview静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!