目录

InnerAudioContext

has.createInnerAudioContext

has.createInnerAudioContext():InnerAudioContext

Creates an InnerAudioContext object of the internal audio component.

Since: 1.0.14

Returns

InnerAudioContext object.

Example:

const ctx = has.createInnerAudioContext();

InnerAudioContext

InnerAudioContext instance, which can be obtained through has.createInnerAudioContext. Note that audio playback may be interrupted during the system. You can handle this situation using the has.onAudioInterruptionBegin and has.onAudioInterruptionEnd events.

Since: 1.0.14

Attributes

Attribute Type Default Value Mandatory Read-Only Description
src string - Yes No Address of the audio to be played.
startTime number 0 No No Position where playback starts, in seconds.
autoplay boolean false No No Whether to automatically start playback. (It is write-only.)
loop boolean false No No Whether to play in a loop.
volume number 1 No No Volume. The value ranges from 0 to 1.
playbackRate number 1 No No Recording playback speed. The supported values are 0.125, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, and 2.
duration number - No Yes Total duration of the audio, in seconds. A value is returned only when src is valid.
currentTime number - No No Current audio playback position, in seconds. A value is returned only when src is valid. It is both readable and writable. Changing the value of currentTime is equivalent to calling seek.
paused boolean - No Yes Whether audio playback is paused or stopped.
buffered number - No Yes Buffered time point of the audio. Only the content from the current playback position to this point is buffered.

[h2]InnerAudioContext.destroy

InnerAudioContext.destroy(): void

Destroys this instance.

Since: 1.0.14

Example:

const ctx = has.createInnerAudioContext();
ctx.destroy();

[h2]InnerAudioContext.play

InnerAudioContext.play(): void

Plays audio.

Since: 1.0.14

Example:

const ctx = has.createInnerAudioContext();
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.pause

InnerAudioContext.pause(): void

Pauses playback. When resumed, playback continues from the position where it was paused.

Since: 1.0.14

Example:

const ctx = has.createInnerAudioContext();
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.pause();
ctx.play(); // When resumed, playback will continue from the point where it was paused.

[h2]InnerAudioContext.seek

InnerAudioContext.seek(number position): void

Seeks to a specified playback position.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
position number Yes Playback position to seek to, in seconds. The value is accurate to three decimal places, that is, millisecond-level precision.

Example:

const ctx = has.createInnerAudioContext();
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.seek(10);

[h2]InnerAudioContext.stop

InnerAudioContext.stop(): void

Stops playback. When playback starts again, it begins from the start of the audio.

Since: 1.0.14

Example:

const ctx = has.createInnerAudioContext();
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.stop();
ctx.play(); // When played again, the audio will restart from the beginning.

[h2]InnerAudioContext.onCanplay

InnerAudioContext.onCanplay(function callback): void

Listens for events indicating that the audio is ready for playback. Such events do not mean that the audio can always play smoothly.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for events indicating that the audio is ready for playback.

Example:

const ctx = has.createInnerAudioContext();
ctx.onCanplay(() => {
   // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.offCanplay

InnerAudioContext.offCanplay(function callback): void

Cancels listening for events indicating that the audio is ready for playback.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onCanplay. If this parameter is not passed, all listener functions are removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = ()=>{
  // Listener function.
};
ctx.onCanplay(callback);
ctx.offCanplay(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.onEnded

InnerAudioContext.onEnded(function callback): void

Listens for events indicating that audio playback ends naturally.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for events indicating that audio playback ends naturally.

Example:

const ctx = has.createInnerAudioContext();
ctx.onEnded(() => {
  // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.offEnded

InnerAudioContext.offEnded(function callback): void

Cancels listening for events indicating that audio playback ends naturally.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onEnded. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = ()=>{
  // Listener function.
};
ctx.onEnded(callback);
ctx.offEnded(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.onError

InnerAudioContext.onError(function callback(res: result)): void

Listens for audio playback error events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for audio playback error events.

Result

Parameter Type Description
errMsg string Error message.
errCode number Error code.

Example:

const ctx = has.createInnerAudioContext();
ctx.onError((res) => {
  // Listener function.
  console.error(res.errMsg);
  console.error(res.errCode);
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.offError

InnerAudioContext.offError(function callback): void

Cancels listening for audio playback error events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onError. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = (res)=>{
  // Listener function.
  console.error(res.errMsg);
  console.error(res.errCode);
};
ctx.onError(callback);
ctx.offError(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.onPause

InnerAudioContext.onPause(function callback): void

Listens for audio playback pause events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for audio playback pause events.

Example:

const ctx = has.createInnerAudioContext();
ctx.onPause(() => {
  // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.pause();

[h2]InnerAudioContext.offPause

InnerAudioContext.offPause(function callback): void

Cancels listening for audio playback pause events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onPause. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = ()=>{
  // Listener function.
};
ctx.onPause(callback);
ctx.offPause(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.pause();

[h2]InnerAudioContext.onPlay

InnerAudioContext.onPlay(function callback): void

Listens for audio playback start events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for audio playback start events.

Example:

const ctx = has.createInnerAudioContext();
ctx.onPlay(() => {
  // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.offPlay

InnerAudioContext.offPlay(function callback): void

Cancels listening for audio playback start events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onPlay. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = ()=>{
  // Listener function.
};
ctx.onPlay(callback);
ctx.offPlay(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.onSeeked

InnerAudioContext.onSeeked(function callback): void

Listens for events indicating that a seek operation on the audio is completed.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for events indicating that a seek operation on the audio is completed.

Example:

const ctx = has.createInnerAudioContext();
ctx.onSeeked(() => {
  // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.seek(10);

[h2]InnerAudioContext.offSeeked

InnerAudioContext.offSeeked(function callback): void

Cancels listening for events indicating that a seek operation on the audio is completed.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onSeeked. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = ()=>{
  // Listener function.
};
ctx.onSeeked(callback);
ctx.offSeeked(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.seek(10);

[h2]InnerAudioContext.onSeeking

InnerAudioContext.onSeeking(function callback): void

Listens for events indicating that a seek operation is initiated on the audio.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for events indicating that a seek operation is initiated on the audio.

Example:

const ctx = has.createInnerAudioContext();
ctx.onSeeking(() => {
  // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.seek(10);

[h2]InnerAudioContext.offSeeking

InnerAudioContext.offSeeking(function callback): void

Cancels listening for events indicating that a seek operation is initiated on the audio.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onSeeking. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = ()=>{
  // Listener function.
};
ctx.onSeeking(callback);
ctx.offSeeking(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.seek(10);

[h2]InnerAudioContext.onStop

InnerAudioContext.onStop(function callback): void

Listens for audio playback stop events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for audio playback stop events.

Example:

const ctx = has.createInnerAudioContext();
ctx.onStop(() => {
  // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.stop();

[h2]InnerAudioContext.offStop

InnerAudioContext.offStop(function callback): void

Canceling listening for audio playback stop events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onStop. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = ()=>{
  // Listener function.
};
ctx.onStop(callback);
ctx.offStop(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();
ctx.stop();

[h2]InnerAudioContext.onTimeUpdate

InnerAudioContext.onTimeUpdate(function callback): void

Listens for events indicating that the audio playback progress is updated.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for audio playback progress update events.

Example:

const ctx = has.createInnerAudioContext();
ctx.onTimeUpdate(() => {
  // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.offTimeUpdate

InnerAudioContext.offTimeUpdate(function callback): void

Cancels listening for events indicating that the audio playback progress is updated.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onTimeUpdate. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = ()=>{
  // Listener function.
};
ctx.onTimeUpdate(callback);
ctx.offTimeUpdate(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.onWaiting

InnerAudioContext.onWaiting(function callback): void

Listens for audio loading events. This event occurs when audio playback is interrupted due to insufficient data and buffering is required.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function Yes Listener function for audio loading events.

Example:

const ctx = has.createInnerAudioContext();
ctx.onWaiting(() => {
  // Listener function.
});
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();

[h2]InnerAudioContext.offWaiting

InnerAudioContext.offWaiting(function callback): void

Cancels listening for audio loading events.

Since: 1.0.14

Parameters

Parameter Type Mandatory Description
callback function No Listener function passed by InnerAudioContext.onWaiting. If this parameter is not passed, all listener functions will be removed.

Example:

const ctx = has.createInnerAudioContext();
const callback = () => {
  // Listener function.
};
ctx.onWaiting(callback);
ctx.offWaiting(callback);
ctx.src = 'xxx'; // Use the real audio resource address during development.
ctx.play();