has.createAudioContext(string id): AudioContext
Creates an AudioContext object of the internal audio component.
Since: 1.0.16
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| id | string | Yes | ID of the audio component. |
Returns
AudioContext object.
Example:
const audioContext = has.createAudioContext('myAudio'); AudioContext instance, which can be obtained by calling has.createAudioContext.
AudioContext is bound to an audio component by ID to operate the corresponding audio component.
Since: 1.0.16
AudioContext.setSrc(string src): void
Sets the audio address.
Since: 1.0.16
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| src | string | Yes | Audio address. |
Example:
const audioContext = has.createAudioContext('myAudio');
audioContext.setSrc('https://www.example.com/test.mp3'); // Replace the example URL with the actual URL.
audioContext.play(); AudioContext.play(): void
Plays audio.
Since: 1.0.16
Example:
const audioContext = has.createAudioContext('myAudio');
audioContext.setSrc('https://www.example.com/test.mp3'); // Replace the example URL with the actual URL.
audioContext.play(); AudioContext.pause(): void
Pauses audio playback.
Since: 1.0.16
Example:
const audioContext = has.createAudioContext('myAudio');
audioContext.setSrc('https://www.example.com/test.mp3'); // Replace the example URL with the actual URL.
audioContext.pause(); AudioContext.seek(number position): void
Seeks to a specified playback position.
Since: 1.0.16
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| position | number | Yes | Target position, in seconds. |
Example:
const audioContext = has.createAudioContext('myAudio');
audioContext.setSrc('https://www.example.com/test.mp3'); // Replace the example URL with the actual URL.
audioContext.seek(20);