android - 在 Android 应用中静音 webview

标签 android audio webview volume mute

我正在构建一个包含一些 WebViews 的应用。

我想将其中一个静音(不是整个应用程序或设备,只是那个特定的 WebView)我搜索过,但这个问题没有确定的答案。 有没有人知道如何在 Android 中使 WebView 声音静音?

最佳答案

您不能仅将 WebView 音量静音,但可以在显示 WebView 时将整个系统音量静音。喜欢 :
当您显示特定的 WebView 时,请使用以下方法:

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 未显示时设置最大音量 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);
}

如果您不想设置完整音量,您可以通过以下方式获取当前系统音量

mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

并将其保存在本地,并在退出 Webview 时重新设置。

关于android - 在 Android 应用中静音 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41676323/

相关文章:

iphone - 当我使用Finch播放音频时,我真的可以做OpenAL可以做的所有事情吗?

android - PictureListener 已弃用和过时,有替代品吗?

android - PhoneGap - 构建 phonegap android 应用程序会在 Linux 上产生编译错误

java - 刷新 Android 3.0 中的 Action Bar

android - 通过 Intent 共享照片时删除了 EXIF 位置数据

c# - 如何在 C#、.NET 中播放声音

Android 运行时异常 : Unable to instantiate the service

python - 每秒获取音频文件的最大振幅

android - 在 CoordinatorLayout 中使用 WebView 的 SwipeRefreshLayout

javascript - 安卓、苹果登录