Audio Playback
WdAudio
Property Description
External properties received by the component
Property Name | Property Identifier | Type | Description |
|---|
| Template | template | string | Designate an audio template Example: "normal" |
| audio resource | src | string | Domain names or IP addresses of audio resources for playing directly, support Cloud File ID Example: "https://qcloudimg.tencent-cloud.cn/raw/472043e1e13e1cc06e4afc46407e8c4d.mp4" |
| autoplay | autoplay | boolean | When interactive behavior exists between the user and the web page, autoplay is enabled. Example: false |
| loop playback | loop | boolean | Example: false |
| playback speed | playbackRate | number | Example: 1 |
| Start playback position (unit: s) | startTime | number | Example: 0 |
Event Description
Events exposed by the component. You can listen to component events to trigger external actions
Event Name | Event Code | Event Output Parameters event.detail | Applicable Scenarios | Description |
|---|
| audio instance initialization complete | audioReady | object
| Compatible with all platforms | Trigger upon completion of audio instance initialization |
| start/continue playback | play | Compatible with all platforms | Trigger the play event when start/continue playback | |
| stop playback | stop | Compatible with all platforms | Trigger the stop event when stopping playback | |
| pause playback | pause | Compatible with all platforms | Trigger the pause event when pausing playback | |
| playback error | error | object
| Compatible with all platforms | Trigger an error event when an error occurs. Mini program event description: https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.onError.html |
| Navigate to specified position | seeked | object
| Compatible with all platforms | Audio skip to specified position triggers seek event |
| Play to the end | ended | Compatible with all platforms | Trigger the ended event at the end of playback | |
| playback progress adjustment | timeupdate | object
| Compatible with all platforms | Trigger when playback progress changes, event.detail = {currentTime, duration} |
Property API
Through the Property API, you can access the internal state and property values of components. You can access internal values using$w.componentId.propertyName, such as $w.input1.value. For details, please refer to Property API
Read-only Property Name | Property Identifier | Type | Description |
|---|
| Audio instance | audioInstance | object | Retrieve the reference of the Audio instance. The current attribute list only shows some key attributes. For more attributes and methods, refer to WeChat Mini Program Documentation. |
| Return the current playback time of the media element in 00:00 format | currentTimeStr | string | |
| 00:00 format for media length | durationStr | string | |
| Whether playing | played | boolean |
Method API
Through the Method API, you can programmatically trigger internal methods of components, such as submitting forms, displaying popups, etc. You can call component methods using $w.componentId.methodName, such as $w.form1.submit()
Method Name | Method Identifier | Parameters | Method Description |
|---|
| play audio | play | Use `$w.audio1.play()` to play audio. See the mini program API document: https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.play.html | |
| pause playback | pause | Use `$w.audio1.pause()` to pause playback. Mini Program API document: https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.pause.html | |
| stop playback | stop | Use `$w.audio1.stop()` to stop playback. The audio will replay from the beginning after stopping. Mini Program API document: https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.stop.html | |
| Navigate to specified position | seek | object
| Use `$w.audio1.seek({ position })` to navigate to the specified position. See the mini program API document: https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.seek.html |
| fast-forward | fastForward | object
| Fast forward for a specified time with $w.audio1.fastForward({ time }) |
| Refund now | backward | object
| Rewind for a specified time with $w.audio1.backward({ time }) |
| Terminate the current instance | destroy | Use `$w.audio1.destroy()` to terminate the current instance. Mini Program API document: https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.destroy.html | |
| Reinitialize the current instance | init | Reinitialize the current instance with $w.audio1.init(), suitable for reinitialization after $w.audio1.destroy(). |
Style API
Through the Style API, you can override the styles of internal elements in components to achieve customization. For example, in the low-code editor, you can write styles for all button components using #wd-page-root .wd-btn, and control individual component styles with :scope. For detailed instructions, please refer toStyle API
Name | Class Name | Description and Examples |
|---|
| root element | .wd-audio | audio component root element |
| PC-side audio component root element | .wd-pc-audio | Write styles for audio on the PC side |
| H5 audio component root element | .wd-h5-audio | Write styles for audio on the H5 side |
| Mini program audio component root element | .wd-mp-audio | Write style for mini program audio |