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 play on load when scene deffer loading #6412

Merged
merged 1 commit into from Mar 25, 2020
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 @@ -121,7 +121,8 @@ Audio.State = {
if (this._nextTime !== 0) {
this.setCurrentTime(this._nextTime);
}
if (this.getState() === Audio.State.PLAYING) {
// need to skip forceUpdatingState when get state on load, because it's a hack operation
if (this.getState(false) === Audio.State.PLAYING) {
this.play();
}
else {
Expand Down Expand Up @@ -271,10 +272,12 @@ Audio.State = {
return this._element ? this._element.duration : 0;
};

proto.getState = function () {
proto.getState = function (forceUpdating = true) {
// HACK: in some browser, audio may not fire 'ended' event
// so we need to force updating the Audio state
this._forceUpdatingState();
if (forceUpdating) {
this._forceUpdatingState();
}

return this._state;
};
Expand Down