Skip to content

Commit

Permalink
update audio state onEnded (cocos#3686)
Browse files Browse the repository at this point in the history
  • Loading branch information
PPpro authored and pandamicro committed Dec 27, 2018
1 parent e6d74d3 commit 2c94ef0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cocos2d/audio/CCAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ let Audio = function (src) {
this._state = Audio.State.INITIALZING;

this._onended = function () {
this._state = Audio.State.STOPPED;
this.emit('ended');
}.bind(this);
};
Expand Down Expand Up @@ -236,6 +237,8 @@ Audio.State = {
}

if (!(CC_QQPLAY || CC_WECHATGAME)) {
// setCurrentTime would fire 'ended' event
// so we need to change the callback to rebind ended callback after setCurrentTime
this._unbindEnded();
this._bindEnded(function () {
this._bindEnded();
Expand Down Expand Up @@ -265,9 +268,11 @@ Audio.State = {

proto.getState = function () {
if (!CC_WECHATGAME && !CC_QQPLAY) {
// 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) {
this._state = Audio.State.PAUSED;
this._state = Audio.State.STOPPED;
}
}
return this._state;
Expand Down

0 comments on commit 2c94ef0

Please sign in to comment.