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

Conversation

@umbrellaPP
Copy link
Contributor

umbrellaPP commented Oct 11, 2019

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

changeLog:

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

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

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

delete _defaultProfileHelper;
_defaultProfileHelper = nullptr;

if (_onPauseListenerID != 0)

This comment has been minimized.

Copy link
@holycanvas

holycanvas Oct 12, 2019

Contributor

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

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

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Oct 12, 2019

Author Contributor

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

@minggo minggo merged commit add0759 into cocos-creator:v2.2.0-release Oct 12, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@JerrifeChoo

This comment has been minimized.

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

This comment has been minimized.

Copy link

JerrifeChoo commented Nov 9, 2019

@umbrellaPP

This comment has been minimized.

Copy link
Contributor Author

umbrellaPP commented Nov 11, 2019

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

@umbrellaPP umbrellaPP deleted the umbrellaPP:22_audio branch Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.