Skip to content

Conversation

@CatEatFishs
Copy link

实例:我依赖了 FlutterPerfectVolumeControl 插件,当我在听歌时,打开我的App,则会中断我的音乐播放。
原因:当plugin 调用 register()时,会调用AVAudioSession.sharedInstance().setActive(true)方法,如果此时其他音频正在播放音乐(QQ音乐),则会暂停其他音频。
解决方案:把设置 setActive() 方法提取出来作为公共方法,让开发人员自由选择,默认false 不做处理。
setActive(true) 抢夺音频焦点,中断其他音频,
setActive(false)不会抢夺音频焦点
建议:我只是简单处理了一下,还有其他 Category,需要设置。

实例:我依赖了 FlutterPerfectVolumeControl 插件,当我在听歌时,打开我的App,则会中断我的音乐播放。
原因:当plugin 调用 register()时,会调用AVAudioSession.sharedInstance().setActive(true)方法,如果此时其他音频正在播放音乐(QQ音乐),则会暂停其他音频。
解决方案:把设置 setActive() 方法提取出来作为公共方法,让开发人员自由选择,默认false 不做处理。
setActive(true) 抢夺音频焦点,中断其他音频,
setActive(false)不会抢夺音频焦点
建议:我只是简单处理了一下,还有其他 Category,需要设置。
@JiangJuHong
Copy link
Owner

I'll check it and merge it.

@JiangJuHong
Copy link
Owner

It works on Ios, but it doesn't work on android. I'll try to unify it. Do you have a better way to unify it?

@CatEatFishs
Copy link
Author

是的,预期是这样的。这个设置active方法只针对ios,对安卓不起作用。
如果安卓要暂停播放,就需要实现其他方法了。

@JiangJuHong JiangJuHong linked an issue Mar 6, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ios Pause other audio

2 participants