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 get auido state bug #3974

Merged
merged 1 commit into from Mar 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions cocos2d/audio/CCAudio.js
Expand Up @@ -267,13 +267,16 @@ Audio.State = {
};

proto.getState = function () {
if (!CC_WECHATGAME && !CC_QQPLAY) {
let elem = this._element;
if (!CC_WECHATGAME && !CC_QQPLAY && elem) {
// HACK: in some browser, audio may not fire 'ended' event
// so we need to force updating the Audio state
let elem = this._element;
if (elem && Audio.State.PLAYING === this._state && elem.paused) {
if (Audio.State.PLAYING === this._state && elem.paused) {
this._state = Audio.State.STOPPED;
}
else if (Audio.State.STOPPED === this._state && !elem.paused) {
Copy link
Contributor

Choose a reason for hiding this comment

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

其实这一段是因为有些浏览器里的 audio 不会触发 ended 事件
所以才需要强制将 audio 的状态更新为 STOPPED

PLAYING 状态可以不用考虑

Copy link
Contributor Author

@knoxHuang knoxHuang Mar 6, 2019

Choose a reason for hiding this comment

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

这里考虑到了 AudioSources 组件的情况,用的是同一个 audio,这样会导致第二个 play 的话,在获取 state 状态就错了

this._state = Audio.State.PLAYING;
}
}
return this._state;
};
Expand Down