AudioContext
Introduction
AudioContext instances can be obtained through dlt.createAudioContext
.
AudioContext is bound to an audio component through id
, and operates on the corresponding audio component.
Usage restrictions
The basic library supports version 6.4.0
or higher.
IDE supports version 0.15.0
or higher.
Methods
AudioContext.play()
Play the audio.
AudioContext.pause()
Pause the audio.
AudioContext.stop()
Stop the audio.
AudioContext.seek(number position)
Jump to a specified position.
Sample code
<!--index.dlt-->
<audio :src="src" id="myAudio"></audio>
<view bind:tap="play"> Click to play </view>
<view bind:tap="pause"> Click to pause </view>
<view bind:tap="stop"> Click to stop </view>
<view bind:tap="seek"> Jump to a specified position </view>
// index.js
Page({
data: {
src: "xxxx.mp3",
},
onLoad() {
this.audioContext = dlt.createAudioContext('myAudio')
},
// Call audio methods through audioContext
play(){
this.audioContext && this.audioContext.play();
},
pause(){
this.audioContext && this.audioContext.pause();
},
stop(){
this.audioContext && this.audioContext.stop();
},
seek(){
// Set the playback progress to the position of 10 seconds
this.audioContext && this.audioContext.seek(10);
},
});