Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix audio stop after answering the phone call #4757

Merged
merged 1 commit into from Jul 1, 2019

Conversation

@PPpro
Copy link
Contributor

@PPpro PPpro commented Jun 29, 2019

Re: cocos-creator/2d-tasks#1395

changeLog:

  • 修复微信平台,接听语音电话之后,音频不再继续播放的问题

在微信平台,提供了独立的 wx.onAudioInterruptionBegin 接口来监听 闹钟、电话、FaceTime 通话、微信语音聊天、微信视频聊天 等事件,实际上这些事件在引擎里应该都归为 event_hide 事件

wx.onHide && wx.onHide(onHidden);
wx.onAudioInterruptionBegin && wx.onAudioInterruptionBegin(onHidden);
Copy link
Contributor Author

@PPpro PPpro Jun 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分修复之后在 2.2 版本应该移入 adapter

Loading

Copy link
Contributor

@knoxHuang knoxHuang Jun 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果接电话不会触发 onHide,那就没啥问题了 @pandamicro 你觉得呢?

Loading

Copy link
Member

@pandamicro pandamicro Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我不清楚这个问题的缘由,也不清楚为什么在 interruption 的时候主动调用 hidden 和 show

Loading

Copy link
Contributor Author

@PPpro PPpro Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interruption 之后,微信会自动停止所有的音频播放,但是接听语音结束后,需要手动调用 audio.play() 才能继续播放

这个逻辑跟 hidden 和 show 是一样的 @pandamicro

Loading

Copy link
Contributor Author

@PPpro PPpro Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是微信 api 文档在这块的描述不是很严格,在安卓上 wx.onAudioInterruptionBegin 接口是无效的,反而 wx.onHide 在接听语音时,有效

Loading

Copy link
Member

@pandamicro pandamicro Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦,看到其他评论了解了,我觉得这个实现没问题

Loading

@PPpro
Copy link
Contributor Author

@PPpro PPpro commented Jun 29, 2019

补充:接听语音,不会触发 wx.onHide 的回调,只会触发 wx.onAudioInterruptionBegin
所以这里不会触发两次

传送门:https://developers.weixin.qq.com/minigame/dev/api/base/app/app-event/wx.onAudioInterruptionBegin.html

Loading

@PPpro
Copy link
Contributor Author

@PPpro PPpro commented Jun 29, 2019

iOS 上的测试结果跟微信文档上的描述相符

安卓上测试情况是,接听语音,小游戏会直接退出后台,会触发 wx.onHide 回调,但是不会触发 wx.onAudioInterruptionBegin

不过不管哪种情况,引擎都有做 hidden 标记,防止重复 触发回调

Loading

wx.onHide && wx.onHide(onHidden);
wx.onAudioInterruptionBegin && wx.onAudioInterruptionBegin(onHidden);
Copy link
Member

@pandamicro pandamicro Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦,看到其他评论了解了,我觉得这个实现没问题

Loading

@PPpro
Copy link
Contributor Author

@PPpro PPpro commented Jul 1, 2019

嗯,没问题的话,就可以先合并了

Loading

@jareguo jareguo merged commit fa55fce into cocos-creator:v2.1.2 Jul 1, 2019
1 check passed
Loading
@jareguo
Copy link
Member

@jareguo jareguo commented Jul 1, 2019

要出版本,先合并了

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants