UNPKG

4.04 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3
4interface AudioProps extends StandardProps {
5 /** audio 组件的唯一标识符
6 * @supported weapp
7 */
8 id?: string
9
10 /** 要播放音频的资源地址
11 * @supported weapp, h5, swan
12 */
13 src?: string
14
15 /** 是否循环播放
16 * @default false
17 * @supported weapp, h5, swan
18 */
19 loop?: boolean
20
21 /** 是否静音播放
22 * @default false
23 * @supported h5
24 * @deprecated
25 */
26 muted?: boolean
27
28 /** 是否显示默认控件
29 * @default false
30 * @supported weapp, h5, swan
31 */
32 controls?: boolean
33
34 /** 默认控件上的音频封面的图片资源地址,如果 controls 属性值为 false 则设置 poster 无效
35 * @supported weapp, swan
36 */
37 poster?: string
38
39 /** 默认控件上的音频名字,如果 controls 属性值为 false 则设置 name 无效
40 * @default "未知音频"
41 * @supported weapp
42 */
43 name?: string
44
45 /** 默认控件上的作者名字,如果 controls 属性值为 false 则设置 author 无效
46 * @default "未知作者"
47 * @supported weapp
48 */
49 author?: string
50
51 /** 当发生错误时触发 error 事件,detail = {errMsg: MediaError.code}
52 * @supported weapp, h5, swan
53 */
54 onError?: CommonEventFunction<AudioProps.onErrorEventDetail>
55
56 /** 当开始/继续播放时触发play事件
57 * @supported weapp, h5, swan
58 */
59 onPlay?: CommonEventFunction
60
61 /** 当暂停播放时触发 pause 事件
62 * @supported weapp, h5, swan
63 */
64 onPause?: CommonEventFunction
65
66 /** 当播放进度改变时触发 timeupdate 事件,detail = {currentTime, duration}
67 * @supported weapp, h5, swan
68 */
69 onTimeUpdate?: CommonEventFunction<AudioProps.onTimeUpdateEventDetail>
70
71 /** 当播放到末尾时触发 ended 事件
72 * @supported weapp, h5, swan
73 */
74 onEnded?: CommonEventFunction
75
76 /** 用于透传 `WebComponents` 上的属性到内部 H5 标签上
77 * @supported h5
78 */
79 nativeProps?: Record<string, unknown>
80}
81
82declare namespace AudioProps {
83 interface onErrorEventDetail {
84 errMsg: keyof MediaError.Code
85 }
86 interface onTimeUpdateEventDetail {
87 /** 当前时间 */
88 currentTime: number
89 /** 持续时间 */
90 duration: number
91 }
92 namespace MediaError {
93 interface Code {
94 /** 获取资源被用户禁止 */
95 1
96 /** 网络错误 */
97 2
98 /** 解码错误 */
99 3
100 /** 不合适资源 */
101 4
102 }
103 }
104}
105
106/** 音频。1.6.0版本开始,该组件不再维护。建议使用能力更强的 Taro.createInnerAudioContext 接口
107 * @classification media
108 * @deprecated
109 * @supported weapp, h5, swan
110 * @example_react
111 * ```tsx
112 * export default class PageView extends Component {
113 * constructor() {
114 * super(...arguments)
115 * }
116 *
117 * render() {
118 * return (
119 * <View className='components-page'>
120 * <Audio
121 * src='https://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46'
122 * controls={true}
123 * autoplay={false}
124 * loop={false}
125 * muted={true}
126 * initialTime='30'
127 * id='video'
128 * />
129 * </View>
130 * )
131 * }
132 * }
133 * ```
134 * @example_vue
135 * ```html
136 * <template>
137 * <view class="components-page">
138 * <audio
139 * id="video"
140 * src="https://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46"
141 * :controls="true"
142 * :autoplay="false"
143 * :loop="false"
144 * :muted="true"
145 * />
146 * </view>
147 * </template>
148 * ```
149 * @see https://developers.weixin.qq.com/miniprogram/dev/component/audio.html
150 */
151declare const Audio: ComponentType<AudioProps>
152
153export { Audio, AudioProps }