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

refine pause playing audio when enter background #1875

Merged
merged 2 commits into from Oct 12, 2019
Merged

refine pause playing audio when enter background #1875

merged 2 commits into from Oct 12, 2019

Conversation

PPpro
Copy link
Contributor

@PPpro PPpro commented Oct 11, 2019

Re: cocos/2d-tasks#1886 cocos/2d-tasks#1806

changeLog:

  • 修复暂停的音频,进入后台再回到前台后,自动恢复播放的问题

进入后台时,应该暂停正在播放的 Audio,回到前台,才恢复播放
最开始这部分逻辑只在安卓上的 AudioEngineImpl 做了,可能是历史遗留问题。。。
把这部分实现挪到最顶层的 AudioEngine 里实现跨平台

@@ -167,6 +171,16 @@ void AudioEngine::end()

delete _defaultProfileHelper;
_defaultProfileHelper = nullptr;

if (_onPauseListenerID != 0)
Copy link
Contributor

@holycanvas holycanvas Oct 12, 2019

Choose a reason for hiding this comment

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

这里貌似只需要判断一次?类似

if (_onPauseListenerID != 0) {
       EventDispatcher::removeCustomEventListener(EVENT_COME_TO_BACKGROUND, _onPauseListenerID);
       EventDispatcher::removeCustomEventListener(EVENT_COME_TO_FOREGROUND, _onResumeListenerID);
}

Copy link
Contributor Author

@PPpro PPpro Oct 12, 2019

Choose a reason for hiding this comment

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

我觉得最好是分开判断,毕竟不是同一个事件

@minggo minggo merged commit add0759 into cocos:v2.2.0-release Oct 12, 2019
1 check passed
@JerrifeChoo
Copy link

JerrifeChoo commented Nov 9, 2019

反馈两个bug:
1、lazyinit,addCustonevent添加前后台监听事件的位置要改一下,目前播放一次就添加一次,可以移到判断是nullptr那边。
2、remove,remove audioid需要同步一下breakAudioID。audiostop之后并不会马上remove,如果切了后台,会被加入到breakAudioID里,然后再掉remove。ios会闪退,最好在remove里把breakAudioID也同步一下。

@JerrifeChoo
Copy link

JerrifeChoo commented Nov 9, 2019

@umbrellaPP

@PPpro
Copy link
Contributor Author

PPpro commented Nov 11, 2019

@JerrifeChoo 感谢反馈,我们之后修复下这两个问题

@PPpro PPpro deleted the 22_audio branch Nov 11, 2019
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.

None yet

5 participants