diff --git a/packages/uni-app-plus/src/service/api/context/getBackgroundAudioManager.ts b/packages/uni-app-plus/src/service/api/context/getBackgroundAudioManager.ts index 5d097802f4fa96aa589f8d0f00e569dd11c31011..6cb1715a6d6c9716f816c6adee773e0dc9996cdf 100644 --- a/packages/uni-app-plus/src/service/api/context/getBackgroundAudioManager.ts +++ b/packages/uni-app-plus/src/service/api/context/getBackgroundAudioManager.ts @@ -1,4 +1,4 @@ -import { extend, capitalize } from '@vue/shared' +import { extend, capitalize, isFunction } from '@vue/shared' import { defineSyncApi, API_GET_BACKGROUND_AUDIO_MANAGER, @@ -157,13 +157,13 @@ function initMusic() { errCode: err.code, }) }) - // @ts-ignore + // @ts-expect-error audio.addEventListener('prev', () => { - onBackgroundAudioPrev() + onBackgroundAudioStateChange({ state: 'prev' }) }) - // @ts-ignore + // @ts-expect-error audio.addEventListener('next', () => { - onBackgroundAudioNext() + onBackgroundAudioStateChange({ state: 'next' }) }) } @@ -290,7 +290,7 @@ function onBackgroundAudioStateChange({ dataUrl?: string }) { callbacks[state].forEach((callback) => { - if (typeof callback === 'function') { + if (isFunction(callback)) { callback( state === 'error' ? { @@ -303,22 +303,6 @@ function onBackgroundAudioStateChange({ }) } -function onBackgroundAudioPrev() { - callbacks['prev'].forEach((callback) => { - if (typeof callback === 'function') { - callback({}) - } - }) -} - -function onBackgroundAudioNext() { - callbacks['next'].forEach((callback) => { - if (typeof callback === 'function') { - callback({}) - } - }) -} - const onInitBackgroundAudioManager = /*#__PURE__*/ once(() => { eventNames.forEach((item) => { BackgroundAudioManager.prototype[`on${capitalize(item)}` as onEventNames] =