getForegroundAudioOption
Introduction
Get the value of a parameter for an audio task.
Parameters
Attribute | Type | Required | Description |
---|---|---|---|
audioPlayerID | String | Yes | The unique identifier of the audio task. |
optionName | String | Yes | The name of the parameter to retrieve. |
success | Function | No | The callback function to execute when the API call is successful. |
fail | Function | No | The callback function to execute when the API call fails. |
complete | Function | No | The callback function to execute when the API call ends (whether successful or failed). |
Available optionName values:
Attribute | Type | Description |
---|---|---|
src | String | The source address of the audio; local file paths only support absolute paths. |
loop | Boolean | Whether to loop the playback. |
autoPlay | Boolean | Whether to enable auto playback. |
volume | Number | The volume level; range from 0 to 1. |
startTime | Number | The starting position of the playback, in seconds. Default is 0. |
duration | Number | The duration of the current audio, in seconds. |
buffered | Number | The time point of the audio buffer; only guarantees that content is buffered until this time point. |
paused | Boolean | Whether the audio is paused. |
currentTime | Number | The current position of the audio playback, in seconds. |
Return Value
Attribute | Description |
---|---|
optionName | Depends on the specific option. |
Example
// pages/index/index.js
Page({
getForegroundAudioOption() {
dlt.getForegroundAudioOption({
audioPlayerID: 'bgmId',
optionName: 'src',
success: function (res) {
console.log('success', res);
},
fail: function () {
console.log('fail');
},
complete: function () {
console.log('complete');
},
});
},
});