From cac55db1c124cadb4c8bbbfb5404a17b4e975302 Mon Sep 17 00:00:00 2001 From: qiang Date: Mon, 20 May 2019 11:58:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20innerAudioContext=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20fixed=20#393?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/service/api/context/inner-audio.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/service/api/context/inner-audio.js b/src/core/service/api/context/inner-audio.js index d7d975d95..ac691cff9 100644 --- a/src/core/service/api/context/inner-audio.js +++ b/src/core/service/api/context/inner-audio.js @@ -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'] + /** * 音频上下文对象 */ @@ -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) + } + } +}) + /** * 创建音频上下文 */ -- GitLab