1.1.3 • Published 6 years ago
taro-audio v1.1.3
代码演示
引入
import AudioPlayer from 'taro-audio';基础用法
通过src属性设置音频资源的地址
<AudioPlayer src={'你的路径'}/>
显示音频名称
通过title属性显示音频名称
<AudioPlayer src={'你的路径'} title='泡沫'/>
显示作者
通过author属性显示作者
<AudioPlayer src={'你的路径'} title='泡沫' author='邓紫棋'/>
自动播放
通过autoplay设置
<AudioPlayer src={'你的路径'} title='泡沫' author='邓紫棋' autoplay />
进度条是否可拖拽
通过draggable设置
<AudioPlayer src={'你的路径'} title='泡沫' author='邓紫棋' autoplay={true} draggable={false}/>
设置海报
通过poster设置
<AudioPlayer src={'你的路径'} title='泡沫' author='邓紫棋' autoplay={false} draggable poster={'你的路径'}/>
Props
| 参数 | 说明 | 类型 | 默认值 | 是否必须 |
|---|---|---|---|---|
| src | 音频资源的地址 | string | 无 | 是 |
| draggable | 是否可以拖动进度条 | boolean | true | 否 |
| title | 音频名称 | string | 无 | 否 |
| author | 音频作者 | string | 无 | 否 |
| autoplay | 是否自动播放 | boolean | false | 否 |
| poster | 音频海报 | string | 无 | 否 |
| onPlay | 当开始/继续播放时触发play事件 | eventHandle | 无 | 否 |
| onPause | 当暂停播放时触发 pause 事件 | eventHandle | 无 | 否 |
| onEnded | 当播放到末尾时触发 ended 事件 | eventHandle | 无 | 否 |
| onTimeUpdate | 当播放进度改变时触发 timeupdate 事件,detail = {currentTime, duration} | eventHandle | 无 | 否 |
| onError | 当发生错误时触发 error 事件,detail = {errMsg:MediaError.code} | eventHandle | 无 | 否 |