将除一个应用程序音频输出以外的所有应用程序音频输出静音
Mute all application audio output except one
我有诸如 spotify、youtube、netflix 等应用程序。
我有我的应用程序。
当我 运行 spotify -> 然后切换到 "my application" 我想在我 watching/listening 在我的应用程序上时将 spotify 声音静音。
如何做到这一点?我试图调查 "AudioManager",但它总是不是一个好的选择,因为你将所有系统静音...
我想确保当我尝试在我的应用程序上收听某些内容时,所有后台应用程序的声音都会被静音。
有人可以至少告诉我方向吗?谢谢。
你试过从 AudioManager 请求 AudioFocus Documentation
如果你能从 Spotify 获取正确的 Stream,它将是 muted.Probably 你应该用 AudioManager.STREAM_MUSIC
给他打电话
除了@Ozan 的回答之外,当一个应用程序获取音频焦点时,它必须能够在另一个应用程序为自己请求音频焦点时释放它。发生这种情况时,您的应用会收到对 AudioFocusChangeListener
中的 onAudioFocusChange()
方法的调用,您在应用调用 requestAudioFocus()
.
时指定了该方法
The focusChange
parameter passed to onAudioFocusChange()
indicates the kind of change that's happening. It corresponds to the duration hint used by the app that's aquiring focus. Your app should respond appropriately.
您也可以查看此相关主题:Android - can I mute currently playing audio applications?
我有诸如 spotify、youtube、netflix 等应用程序。 我有我的应用程序。
当我 运行 spotify -> 然后切换到 "my application" 我想在我 watching/listening 在我的应用程序上时将 spotify 声音静音。
如何做到这一点?我试图调查 "AudioManager",但它总是不是一个好的选择,因为你将所有系统静音...
我想确保当我尝试在我的应用程序上收听某些内容时,所有后台应用程序的声音都会被静音。
有人可以至少告诉我方向吗?谢谢。
你试过从 AudioManager 请求 AudioFocus Documentation
如果你能从 Spotify 获取正确的 Stream,它将是 muted.Probably 你应该用 AudioManager.STREAM_MUSIC
给他打电话除了@Ozan 的回答之外,当一个应用程序获取音频焦点时,它必须能够在另一个应用程序为自己请求音频焦点时释放它。发生这种情况时,您的应用会收到对 AudioFocusChangeListener
中的 onAudioFocusChange()
方法的调用,您在应用调用 requestAudioFocus()
.
The
focusChange
parameter passed toonAudioFocusChange()
indicates the kind of change that's happening. It corresponds to the duration hint used by the app that's aquiring focus. Your app should respond appropriately.
您也可以查看此相关主题:Android - can I mute currently playing audio applications?