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

@umbrellaPP
Copy link
Contributor

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);

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Jun 29, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@knoxHuang

knoxHuang Jun 29, 2019

Collaborator

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

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jul 1, 2019

Member

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

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Jul 1, 2019

Author Contributor

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

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

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Jul 1, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jul 1, 2019

Member

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

@umbrellaPP

This comment has been minimized.

Copy link
Contributor Author

commented Jun 29, 2019

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

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

@umbrellaPP

This comment has been minimized.

Copy link
Contributor Author

commented Jun 29, 2019

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

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

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

wx.onHide && wx.onHide(onHidden);
wx.onAudioInterruptionBegin && wx.onAudioInterruptionBegin(onHidden);

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jul 1, 2019

Member

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

@umbrellaPP

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2019

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

@jareguo jareguo merged commit fa55fce into cocos-creator:v2.1.2 Jul 1, 2019

1 check passed

ci/circleci: test Your tests passed on CircleCI!
Details
@jareguo

This comment has been minimized.

Copy link
Contributor

commented Jul 1, 2019

要出版本,先合并了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.