为什么abandonAudioFocus在Android音乐应用程序中不起作用
我使用此代码来获取 AudioFocus,它可以正常工作
Android 音乐应用程序(预装的)
int result = audioManager.requestAudioFocus(meService, AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
但是当我使用此代码发布它时,
audioManager.abandonAudioFocus(meService);
Android 音乐应用程序(预装的)不会继续播放。
如果我使用AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
它就可以工作
但 Android 音乐应用程序无法充分降低音量。
有什么想法为什么 Android 音乐应用程序不恢复播放吗?
我正在使用 api8 并使用 onAudioFocusChange
Im using this code to get AudioFocus and it works ok with
Android Music app ( the one preinstalled )
int result = audioManager.requestAudioFocus(meService, AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
However when i release it with this code
audioManager.abandonAudioFocus(meService);
The Android Music app ( the one preinstalled ) does not continue playing.
if i use the AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
it works
but Android Music app is not lowering the volume enough.
Any ides why Android Music app is not resuming playback?
im using api8 and using the onAudioFocusChange
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在
MediaPlay.onCompleteListener(){}
中释放它You should release it in
MediaPlay.onCompleteListener(){}
尝试了 4 名玩家后,他们都没有躲闪。我可能做错了什么并且希望看到这一点。我回答我自己的问题,我们必须忍受这一点。
After trying 4 players non of them are ducking. I might be doing something wrong and would like to see that. I answer my own question that we have to live with this.
这种方式对我来说效果很好。
请求 AudioFocus:
放弃 AudioFocus:
希望这对您有帮助。
This way works fine for me.
Request AudioFocus:
Abandon AudioFocus:
Hope this would help you.