跳到主要内容

bn.createInnerAudioContext

createInnerAudioContext(options?): InnerAudioContext

description Creates the context InnerAudioContext object for an internal audio

example

const innerAudioContext = bn.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3'
innerAudioContext.onPlay(() => {
console.log('Start playback')
})
innerAudioContext.onError(res => {
console.log(res.errMsg)
console.log(res.errCode)
})

Parameters

NameTypeDescription
options?CreateInnerAudioContextOptionInnerAudioContext creation options

Returns

InnerAudioContext


Interface: CreateInnerAudioContextOption

NameTypeDescription
useWebAudioImplement?booleanWhether or not to use WebAudio. Turns off by default. For short audio, frequent audio is recommended to enable this option, open will get better performance, for long audio recommended to close this option

Interface: InnerAudioContext

NameTypeDescription
destroy(): voidTerminates the current instance
offCanplay(callback?): voidUnlistens on the event that an audio file is ready for playback
offEnded(callback?): voidUnlistens on the event of playing an audio file to the end without interruption
offError(callback?): voidUnlistens on the audio playback error event
offPause(callback?): voidUnlistens on the audio pause event
offPlay(callback?): voidUnlistens on the audio playback event
offSeeked(callback?): voidUnlistens on the event of finishing the jump to a specific position in the audio file
offSeeking(callback?): voidUnlistens on the event of jumping to a specific position in the audio file
offStop(callback?): voidUnlistens on the event of stopping audio playback
offTimeUpdate(callback?): voidUnlistens on the event of updating audio playback progress.
offWaiting(callback?): voidUnlistens on the audio loading event
onCanplay(callback): voidListens on the event that an audio file is ready for playback. A smooth playback is not guaranteed
onEnded(callback): voidListens on the event of playing an audio file to the end without interruption
onError(callback): voidListens on the audio playback error event
onPause(callback): voidListens on the audio pause event
onPlay(callback): voidListens on the audio playback event
onSeeked(callback): voidListens on the event of finishing the jump to a specific position in the audio file
onSeeking(callback): voidListens on the event of jumping to a specific position in the audio file
onStop(callback): voidListens on the event of stopping audio playback
onTimeUpdate(callback): voidListens on the event of updating audio playback progress
onWaiting(callback): voidListens on the audio loading event. It is triggered when the playback of an audio file stops to load the file due to insufficient data
pause(): voidPauses the audio playback. The playback is resumed at the point where it was paused
play(): voidPlays an audio file
seek(position): voidJumps to the specific position
stop(): voidStops the audio playback. The playback starts from the beginning if the file is played again
autoplaybooleanWhether to enable auto playback. It is false by default
bufferednumberThe position where the audio is buffered. Only the part between the position where the playback has got to and this position is buffered (read only)
currentTimenumberThe position where the playback has got to (in sec). It is only returned when a valid src attribute exists and is rounded to six decimal places (read only)
durationnumberThe length of the audio file (in sec). It is only returned when a valid src attribute exists (read only)
loopbooleanWhether to enable loop playback. It is false by default
obeyMuteSwitchbooleanWhether to follow the "Mute" switch. It is true by default. If it is set to false, the audio file still sounds even if the "Mute" switch is on
pausedbooleanWhether the playback is paused or stopped (read only)
playbackRatenumberSpecifies the playbackRate, which ranges from 0.5 to 2. It is 1 by default
srcstringThe audio file address which can be used to play the audio file directly
startTimenumberThe position where the playback starts (in sec). It is 0 by default
volumenumberSpecifies the volume, which ranges from 0 to 1. It is 1 by default
referrerPolicy"" | "origin" | "no-referrer"referrer policy; origin - send request with referrer; no-referrer - do send with referrer

destroy

destroy(): void

Terminates the current instance

Returns

void


offCanplay

offCanplay(callback?): void

Unlistens on the event that an audio file is ready for playback

Parameters

NameType
callback?OffCanplayCallback

Returns

void


offEnded

offEnded(callback?): void

Unlistens on the event of playing an audio file to the end without interruption

Parameters

NameType
callback?OffEndedCallback

Returns

void


offError

offError(callback?): void

Unlistens on the audio playback error event

Parameters

NameType
callback?OffErrorCallback

Returns

void


offPause

offPause(callback?): void

Unlistens on the audio pause event

Parameters

NameType
callback?OffPauseCallback

Returns

void


offPlay

offPlay(callback?): void

Unlistens on the audio playback event

Parameters

NameType
callback?OffPlayCallback

Returns

void


offSeeked

offSeeked(callback?): void

Unlistens on the event of finishing the jump to a specific position in the audio file

Parameters

NameType
callback?OffSeekedCallback

Returns

void


offSeeking

offSeeking(callback?): void

Unlistens on the event of jumping to a specific position in the audio file

Parameters

NameType
callback?OffSeekingCallback

Returns

void


offStop

offStop(callback?): void

Unlistens on the event of stopping audio playback

Parameters

NameType
callback?OffStopCallback

Returns

void


offTimeUpdate

offTimeUpdate(callback?): void

Unlistens on the event of updating audio playback progress.

Parameters

NameType
callback?OffTimeUpdateCallback

Returns

void


offWaiting

offWaiting(callback?): void

Unlistens on the audio loading event

Parameters

NameType
callback?OffWaitingCallback

Returns

void


onCanplay

onCanplay(callback): void

Listens on the event that an audio file is ready for playback. A smooth playback is not guaranteed

Parameters

NameType
callbackOnCanplayCallback

Returns

void


onEnded

onEnded(callback): void

Listens on the event of playing an audio file to the end without interruption

Parameters

NameType
callbackOnEndedCallback

Returns

void


onError

onError(callback): void

Listens on the audio playback error event

Parameters

NameType
callbackOnErrorCallback

Returns

void


onPause

onPause(callback): void

Listens on the audio pause event

Parameters

NameType
callbackOnPauseCallback

Returns

void


onPlay

onPlay(callback): void

Listens on the audio playback event

Parameters

NameType
callbackOnPlayCallback

Returns

void


onSeeked

onSeeked(callback): void

Listens on the event of finishing the jump to a specific position in the audio file

Parameters

NameType
callbackOnSeekedCallback

Returns

void


onSeeking

onSeeking(callback): void

Listens on the event of jumping to a specific position in the audio file

Parameters

NameType
callbackOnSeekingCallback

Returns

void


onStop

onStop(callback): void

Listens on the event of stopping audio playback

Parameters

NameType
callbackOnStopCallback

Returns

void


onTimeUpdate

onTimeUpdate(callback): void

Listens on the event of updating audio playback progress

Parameters

NameType
callbackOnTimeUpdateCallback

Returns

void


onWaiting

onWaiting(callback): void

Listens on the audio loading event. It is triggered when the playback of an audio file stops to load the file due to insufficient data

Parameters

NameType
callbackOnWaitingCallback

Returns

void


pause

pause(): void

Pauses the audio playback. The playback is resumed at the point where it was paused

Returns

void


play

play(): void

Plays an audio file

Returns

void


seek

seek(position): void

Jumps to the specific position

Parameters

NameType
positionnumber

Returns

void


stop

stop(): void

Stops the audio playback. The playback starts from the beginning if the file is played again

Returns

void