Skip to content

Commit

Permalink
feat: innerAudioContext 实现取消事件监听方法 fixed #393
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed May 20, 2019
1 parent 86e5187 commit cac55db
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/core/service/api/context/inner-audio.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* 可以批量设置的监听事件
*/
var innerAudioContextEventNames = ['onCanplay', 'onPlay', 'onPause', 'onStop', 'onEnded', 'onTimeUpdate', 'onError', 'onWaiting', 'onSeeking', 'onSeeked']
const innerAudioContextEventNames = ['onCanplay', 'onPlay', 'onPause', 'onStop', 'onEnded', 'onTimeUpdate', 'onError', 'onWaiting', 'onSeeking', 'onSeeked']

const innerAudioContextOffEventNames = ['offCanplay', 'offPlay', 'offPause', 'offStop', 'offEnded', 'offTimeUpdate', 'offError', 'offWaiting', 'offSeeking', 'offSeeke']

/**
* 音频上下文对象
*/
Expand Down Expand Up @@ -138,6 +141,17 @@ innerAudioContextEventNames.forEach((eventName) => {
}
})

// 批量设置音频上下文事件取消监听方法
innerAudioContextOffEventNames.forEach((eventName) => {
InnerAudioContext.prototype[eventName] = function (callback) {
var handle = this._events[eventName.replace('off', 'on')]
var index = handle.indexOf(callback)
if (index >= 0) {
handle.splice(index, 1)
}
}
})

/**
* 创建音频上下文
*/
Expand Down

0 comments on commit cac55db

Please sign in to comment.