1 | import { ComponentType } from 'react'
|
2 | import { StandardProps, CommonEventFunction } from './common'
|
3 |
|
4 | interface VideoProps extends StandardProps {
|
5 | /** 要播放视频的资源地址
|
6 | * @supported weapp, h5, swan, alipay, tt, rn
|
7 | */
|
8 | src: string
|
9 |
|
10 | /** 指定视频时长
|
11 | * @supported weapp, swan, alipay, rn
|
12 | * @h5 待定
|
13 | */
|
14 | duration?: number
|
15 |
|
16 | /** 是否显示默认播放控件(播放/暂停按钮、播放进度、时间)
|
17 | * @default true
|
18 | * @supported weapp, h5, swan, alipay, tt, rn
|
19 | */
|
20 | controls?: boolean
|
21 |
|
22 | /** 弹幕列表
|
23 | * @supported weapp, swan
|
24 | * @h5 待定
|
25 | */
|
26 | danmuList?: any[]
|
27 |
|
28 | /** 是否显示弹幕按钮,只在初始化时有效,不能动态变更
|
29 | * @default false
|
30 | * @supported weapp, swan
|
31 | * @h5 待定
|
32 | */
|
33 | danmuBtn?: boolean
|
34 |
|
35 | /** 是否展示弹幕,只在初始化时有效,不能动态变更
|
36 | * @default false
|
37 | * @supported weapp, swan
|
38 | * @h5 待定
|
39 | */
|
40 | enableDanmu?: boolean
|
41 |
|
42 | /** 是否自动播放
|
43 | * @default false
|
44 | * @supported weapp, h5, swan, alipay, tt, rn
|
45 | */
|
46 | autoplay?: boolean
|
47 |
|
48 | /** 是否循环播放
|
49 | * @default false
|
50 | * @supported weapp, h5, swan, alipay, tt, rn
|
51 | */
|
52 | loop?: boolean
|
53 |
|
54 | /** 是否静音播放
|
55 | * @default false
|
56 | * @supported weapp, h5, swan, alipay, tt, rn
|
57 | */
|
58 | muted?: boolean
|
59 |
|
60 | /** 指定视频初始播放位置
|
61 | * @supported weapp, h5, swan, alipay, tt, rn
|
62 | */
|
63 | initialTime?: number
|
64 |
|
65 | /** 在非全屏模式下,是否开启亮度与音量调节手势
|
66 | * @default false
|
67 | * @h5 待定
|
68 | */
|
69 | pageGesture?: boolean
|
70 |
|
71 | /** 设置全屏时视频的方向,不指定则根据宽高比自动判断。有效值为 0(正常竖向), 90(屏幕逆时针90度), -90(屏幕顺时针90度)
|
72 | * @supported weapp, swan, alipay
|
73 | * @h5 待定
|
74 | */
|
75 | direction?: number
|
76 |
|
77 | /** 若不设置,宽度大于240时才会显示
|
78 | * @default true
|
79 | * @supported weapp, swan, tt
|
80 | * @h5 待定
|
81 | */
|
82 | showProgress?: boolean
|
83 |
|
84 | /** 是否显示全屏按钮
|
85 | * @default true
|
86 | * @supported weapp, swan, alipay, tt
|
87 | * @h5 待定
|
88 | */
|
89 | showFullscreenBtn?: boolean
|
90 |
|
91 | /** 是否显示视频底部控制栏的播放按钮
|
92 | * @default true
|
93 | * @supported weapp, swan, alipay, tt
|
94 | * @h5 待定
|
95 | */
|
96 | showPlayBtn?: boolean
|
97 |
|
98 | /** 是否显示视频中间的播放按钮
|
99 | * @default true
|
100 | * @supported weapp, swan, alipay, rn
|
101 | * @h5 待定
|
102 | */
|
103 | showCenterPlayBtn?: boolean
|
104 |
|
105 | /** 是否开启控制进度的手势
|
106 | * @default true
|
107 | * @supported weapp, swan, alipay, tt
|
108 | * @h5 待定
|
109 | */
|
110 | enableProgressGesture?: boolean
|
111 |
|
112 | /** 当视频大小与 video 容器大小不一致时,视频的表现形式
|
113 | * @default "contain"
|
114 | * @supported weapp, swan, alipay, tt
|
115 | * @h5 待定
|
116 | */
|
117 | objectFit?: keyof VideoProps.ObjectFit
|
118 |
|
119 | /** 视频封面的图片网络资源地址,如果 controls 属性值为 false 则设置 poster 无效
|
120 | * @supported weapp, h5, swan, alipay, tt, rn
|
121 | */
|
122 | poster?: string
|
123 |
|
124 | /** 是否显示静音按钮
|
125 | * @default false
|
126 | * @supported weapp, tt
|
127 | * @h5 待定
|
128 | */
|
129 | showMuteBtn?: boolean
|
130 |
|
131 | /** 视频的标题,全屏时在顶部展示
|
132 | * @supported weapp
|
133 | * @h5 待定
|
134 | */
|
135 | title?: string
|
136 |
|
137 | /** 播放按钮的位置
|
138 | * - `bottom`: controls bar 上
|
139 | * - `center`: 视频中间
|
140 | *
|
141 | * @default 'bottom'
|
142 | * @supported weapp, tt
|
143 | * @h5 待定
|
144 | */
|
145 | playBtnPosition?: keyof VideoProps.PlayBtnPosition
|
146 |
|
147 | /** 是否开启播放手势,即双击切换播放/暂停
|
148 | * @default false
|
149 | * @supported weapp, tt
|
150 | * @h5 待定
|
151 | */
|
152 | enablePlayGesture?: boolean
|
153 |
|
154 | /** 当跳转到其它小程序页面时,是否自动暂停本页面的视频
|
155 | * @default true
|
156 | * @supported weapp
|
157 | * @h5 待定
|
158 | */
|
159 | autoPauseIfNavigate?: boolean
|
160 |
|
161 | /** 当跳转到其它微信原生页面时,是否自动暂停本页面的视频
|
162 | * @default true
|
163 | * @supported weapp
|
164 | * @h5 待定
|
165 | */
|
166 | autoPauseIfOpenNative?: boolean
|
167 |
|
168 | /** 在非全屏模式下,是否开启亮度与音量调节手势(同 `page-gesture`)
|
169 | * @default false
|
170 | * @supported weapp, swan, tt
|
171 | * @h5 待定
|
172 | */
|
173 | vslideGesture?: boolean
|
174 |
|
175 | /** 在全屏模式下,是否开启亮度与音量调节手势
|
176 | * @default true
|
177 | * @supported weapp, tt
|
178 | * @h5 待定
|
179 | */
|
180 | vslideGestureInFullscreen?: boolean
|
181 |
|
182 | /** 视频前贴广告单元ID,更多详情可参考开放能力[视频前贴广告](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/ad/video-patch-ad.html)
|
183 | * @supported weapp
|
184 | */
|
185 | adUnitId?: string
|
186 |
|
187 | /** 用于给搜索等场景作为视频封面展示,建议使用无播放 icon 的视频封面图,只支持网络地址
|
188 | * @supported weapp
|
189 | */
|
190 | posterForCrawler?: string
|
191 |
|
192 | /** 显示投屏按钮。只安卓且同层渲染下生效,支持 DLNA 协议
|
193 | * @supported weapp
|
194 | */
|
195 | showCastingButton?: boolean
|
196 |
|
197 | /**
|
198 | * 设置小窗模式: push, pop,空字符串或通过数组形式设置多种模式(如: ["push", "pop"])
|
199 | * @supported weapp
|
200 | */
|
201 | pictureInPictureMode?: ('push' | 'pop')[] | 'push' | 'pop' | ''
|
202 |
|
203 | /**
|
204 | * 是否在小窗模式下显示播放进度(目前有bug,先注释掉)
|
205 | * @supported weapp
|
206 | *
|
207 | * 先注释掉,原因如下:
|
208 | * 该属性超过了 wxml 属性的长度限制,实际无法使用且导致编译报错。可等微信官方修复后再放开。
|
209 | * 参考1:https://developers.weixin.qq.com/community/develop/doc/000a429beb87f0eac07acc0fc5b400
|
210 | * 参考2: https://developers.weixin.qq.com/community/develop/doc/0006883619c48054286a4308258c00?_at=vyxqpllafi
|
211 | *
|
212 | */
|
213 | // pictureInPictureShowProgress?: boolean
|
214 |
|
215 | /**
|
216 | * 是否开启手机横屏时自动全屏,当系统设置开启自动旋转时生效
|
217 | * @supported weapp
|
218 | */
|
219 | enableAutoRotation?: boolean
|
220 |
|
221 | /**
|
222 | * 是否显示锁屏按钮,仅在全屏时显示,锁屏后控制栏的操作
|
223 | * @supported weapp
|
224 | */
|
225 | showScreenLockButton?: boolean
|
226 |
|
227 | /** 当开始/继续播放时触发 play 事件
|
228 | * @supported weapp, h5, swan, alipay, tt, rn
|
229 | */
|
230 | onPlay?: CommonEventFunction
|
231 |
|
232 | /** 当暂停播放时触发 pause 事件
|
233 | * @supported weapp, h5, swan, alipay, tt, rn
|
234 | */
|
235 | onPause?: CommonEventFunction
|
236 |
|
237 | /** 当播放到末尾时触发 ended 事件
|
238 | * @supported weapp, h5, swan, alipay, tt, rn
|
239 | */
|
240 | onEnded?: CommonEventFunction
|
241 |
|
242 | /** 播放进度变化时触发, 触发频率 250ms 一次
|
243 | *
|
244 | * event.detail = {currentTime, duration}
|
245 | * @supported weapp, h5, swan, alipay, tt, rn
|
246 | */
|
247 | onTimeUpdate?: CommonEventFunction<VideoProps.onTimeUpdateEventDetail>
|
248 |
|
249 | /** 当视频进入和退出全屏时触发
|
250 | *
|
251 | * event.detail = {fullScreen, direction},direction取为 vertical 或 horizontal
|
252 | * @supported weapp, swan, alipay, rn, tt
|
253 | * @h5 待定
|
254 | */
|
255 | onFullscreenChange?: CommonEventFunction<VideoProps.onFullscreenChangeEventDetail>
|
256 |
|
257 | /** 当视频进入和退出全屏时触发
|
258 | *
|
259 | * event.detail = {fullScreen, direction},direction 取为 vertical 或 horizontal
|
260 | * @supported weapp, swan, tt
|
261 | * @h5 待定
|
262 | */
|
263 | onWaiting?: CommonEventFunction<VideoProps.onWaitingEventDetail>
|
264 |
|
265 | /** 视频播放出错时触发
|
266 | * @supported weapp, h5, swan, alipay, tt, rn
|
267 | */
|
268 | onError?: CommonEventFunction
|
269 | /** 加载进度变化时触发,只支持一段加载
|
270 | * @supported weapp, alipay
|
271 | * @h5 待定
|
272 | */
|
273 | onProgress?: CommonEventFunction<VideoProps.onProgressEventDetail>
|
274 |
|
275 | /** 视频元数据加载完成时触发。event.detail = {width, height, duration}
|
276 | * @supported weapp, rn, tt
|
277 | */
|
278 | onLoadedMetaData?: CommonEventFunction
|
279 |
|
280 | /**
|
281 | * 切换 controls 显示隐藏时触发。event.detail = {show}
|
282 | * @supported weapp
|
283 | */
|
284 | onControlsToggle?: CommonEventFunction<VideoProps.onControlsToggleEventDetail>
|
285 |
|
286 | /**
|
287 | * 播放器进入小窗
|
288 | * @supported weapp
|
289 | */
|
290 | onEnterPictureInPicture?: CommonEventFunction
|
291 |
|
292 | /**
|
293 | * 播放器退出小窗
|
294 | * @supported weapp
|
295 | */
|
296 | onLeavePictureInPicture?: CommonEventFunction
|
297 |
|
298 | /**
|
299 | * seek 完成时触发
|
300 | * @supported weapp
|
301 | */
|
302 | onSeekComplete?: CommonEventFunction
|
303 |
|
304 | /** 用于透传 `WebComponents` 上的属性到内部 H5 标签上
|
305 | * @supported h5
|
306 | */
|
307 | nativeProps?: Record<string, unknown>
|
308 | }
|
309 |
|
310 | declare namespace VideoProps {
|
311 | /** direction 的合法值 */
|
312 | interface direction {
|
313 | /** 正常竖向 */
|
314 | 0
|
315 | /** 屏幕逆时针90度 */
|
316 | 90
|
317 | /** 屏幕顺时针90度 */
|
318 | '-90'
|
319 | }
|
320 | /** objectFit 的合法值 */
|
321 | interface ObjectFit {
|
322 | /** 包含 */
|
323 | contain
|
324 | /** 填充 */
|
325 | fill
|
326 | /** 覆盖 */
|
327 | cover
|
328 | }
|
329 | /** playBtnPosition 的合法值 */
|
330 | interface PlayBtnPosition {
|
331 | /** controls bar上 */
|
332 | bottom
|
333 | /** 视频中间 */
|
334 | center
|
335 | }
|
336 |
|
337 | interface onTimeUpdateEventDetail {
|
338 | /** 当前时间 */
|
339 | currentTime: number
|
340 | /** 持续时间 */
|
341 | duration: number
|
342 | }
|
343 | interface onFullscreenChangeEventDetail {
|
344 | /** 方向 */
|
345 | direction: number
|
346 | /** 全屏 */
|
347 | fullScreen: number | boolean
|
348 | }
|
349 | interface onWaitingEventDetail {
|
350 | /** 方向 */
|
351 | direction: number
|
352 | /** 全屏 */
|
353 | fullScreen: number | boolean
|
354 | }
|
355 | interface onProgressEventDetail {
|
356 | /** 百分比 */
|
357 | buffered: number
|
358 | }
|
359 |
|
360 | interface onControlsToggleEventDetail {
|
361 | /** 是否显示 */
|
362 | show: boolean
|
363 | }
|
364 | }
|
365 |
|
366 | /** 视频。相关api:Taro.createVideoContext
|
367 | *
|
368 | * 备注:h5上因为没有测试,所以暂时写了“待定”,需要`Video`来确认。
|
369 | * @classification media
|
370 | * @supported weapp, h5, swan, alipay, tt
|
371 | * @example_react
|
372 | * ```tsx
|
373 | * export default class PageView extends Component {
|
374 | * constructor() {
|
375 | * super(...arguments)
|
376 | * }
|
377 | *
|
378 | * render() {
|
379 | * return (
|
380 | * <View className='components-page'>
|
381 | * <Video
|
382 | * id='video'
|
383 | * src='https://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400'
|
384 | * poster='https://misc.aotu.io/booxood/mobile-video/cover_900x500.jpg'
|
385 | * initialTime={0}
|
386 | * controls={true}
|
387 | * autoplay={false}
|
388 | * loop={false}
|
389 | * muted={false}
|
390 | * />
|
391 | * </View>
|
392 | * )
|
393 | * }
|
394 | * }
|
395 | * ```
|
396 | * @example_vue
|
397 | * ```html
|
398 | * <template>
|
399 | * <video
|
400 | * id="video"
|
401 | * src="https://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400"
|
402 | * poster="https://misc.aotu.io/booxood/mobile-video/cover_900x500.jpg"
|
403 | * initial-time="0"
|
404 | * :controls="true"
|
405 | * :autoplay="false"
|
406 | * :loop="false"
|
407 | * :muted="false"
|
408 | * />
|
409 | * </template>
|
410 | * ```
|
411 | * @see https://developers.weixin.qq.com/miniprogram/dev/component/video.html
|
412 | */
|
413 | declare const Video: ComponentType<VideoProps>
|
414 |
|
415 | export { Video, VideoProps }
|