HomeDocs
Skip to main content

audio - Audio Component

Introduction

audio component.

Starting from version 6.4.0 of the basic library, dlt.createAudioContext is supported to operate on the audio component.

Usage restrictions

The basic library supports version 6.4.0 or higher.
IDE supports version0.15.0 or higher.

Properties

Property NameTypeDefault ValueRequiredDescriptionMinimum Version
srcstringYesThe resource address of the audio to be played, supports network paths and local paths6.4.0
loopbooleanfalseNoWhether to loop playback6.4.0
mutedbooleanfalseNoWhether to mute playback6.4.0
controlsbooleantrueNoWhether to display the default playback controls6.4.0
autoplaybooleanfalseNoWhether to autoplay6.4.0
bindplayeventhandleNoTrigger a play event when starting/continuing to play6.4.0
bindpauseeventhandleNoTrigger a pause event when pausing playback6.4.0
bindendedeventhandleNoTrigger an ended event when playing to the end6.4.0
bindtimeupdateeventhandleNoTriggered when the playback progress changes, event.detail = {currentTime, duration}. Trigger frequency is once every 250ms6.4.0
bindwaitingeventhandleNoTriggered when the audio is buffering6.4.0
binderroreventhandleNoTriggered when the audio playback error6.4.0
bindprogresseventhandleNoTriggered when the loading progress changes, only supports one segment loading.6.4.0
bindloadedmetadataeventhandleNoTriggered when the audio metadata is loaded. event.detail = {width, height, duration}, width, height are the internal width and height of the control element6.4.0
bindcontrolstoggleeventhandleNoTriggered when toggling controls display and hide.6.4.0
bindseekcompleteeventhandleNoTriggered when seek is complete6.4.0
bindmutedchangeeventhandleNoTriggered when the audio is muted. event.detail = {muted: true}, muted is true when the current audio is muted, and false when it is not muted6.4.0

Usage Example

 <audio  
id="myAudio"
:src="src"
:autoplay="autoplay"
:muted="muted"
:loop="loop"
:controls="controls"
bind:bindtimeupdate="bindtimeupdate"
bind:bindplay="bindplay"
bind:bindloadedmetadata="bindloadedmetadata"
bind:bindseeked="bindseeked"
bind:bindwaiting="bindwaiting"
bind:bindprogress="bindprogress"
bind:bindcontrolstoggle="bindcontrolstoggle"
bind:bindmutedchange="bindmutedchange"
>
</audio>

// index.js
Page({
data: {
autoplay:false,
controls:true,
muted:true,
loop:true,
src:"/images/xxxx.mp3", // "https://xxxx/xxxx.mp3"
},
onLoad() {
this.audio = dlt.createAudioContext("myAudio")
},
bindplay(event) {
console.log("bindplay",event);
},
bindpause(event) {
console.log("bindpause",event);
},
bindended(event) {
console.log("bindended",event);
},
binderror(event) {
console.log("binderror",event);
},
bindtimeupdate(event) {
console.log("bindtimeupdate",event);
},
bindmutedchange(event){
console.log("Whether the current audio is muted:",evnet.detail.muted)
}
});

/**
* event example:
{
detail: {
currentTime: 0.871904,
duration: 60.095011,
height: 54,
width: 300,
},
target: {
dataset: {
content: "data--detail-content",
url: "data--url--content",
},
id: "myAudio",
},
timeStamp: 11574.799999982119,
type: "timeupdate",
}
*/

Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.