Video
是ArkUI开发框架提供的一个视频播放组件,我们可以使用该组件实现播放视频相关的功能,本节笔者简单介绍一下 Video
的使用。
interface VideoInterface {
(value: VideoOptions): VideoAttribute;// Video创建需要传递一个必要参数value
}
declare interface VideoOptions {
src?: string | Resource;
currentProgressRate?: number | string | PlaybackSpeed;
previewUri?: string | PixelMap | Resource;
controller?: VideoController;
}
VideoOptions
参数说明如下:0.75
, 1.0
, 1.25
, 1.75
, 2.0
。declare class VideoAttribute extends CommonMethod<VideoAttribute> {
muted(value: boolean): VideoAttribute;
autoPlay(value: boolean): VideoAttribute;
controls(value: boolean): VideoAttribute;
loop(value: boolean): VideoAttribute;
objectFit(value: ImageFit): VideoAttribute;
}
Image
组件的 ImageFit
属性。declare class VideoAttribute extends CommonMethod<VideoAttribute> {
onStart(event: () => void): VideoAttribute;
onPause(event: () => void): VideoAttribute;
onFinish(event: () => void): VideoAttribute;
onFullscreenChange(callback: (event?: { fullscreen: boolean }) => void): VideoAttribute;
onPrepared(callback: (event?: { duration: number }) => void): VideoAttribute;
onSeeking(callback: (event?: { time: number }) => void): VideoAttribute;
onSeeked(callback: (event?: { time: number }) => void): VideoAttribute;
onUpdate(callback: (event?: { time: number }) => void): VideoAttribute;
onError(event: () => void): VideoAttribute;
}
@Entry @Component struct ArkUIClubTest {
private videoController: VideoController = new VideoController()
build() {
Column({space: 10}) {
Video({
src: $rawfile("test_video.mp4"), // 设置数据源
previewUri: "https://www.arkui.club/img/test.png", // 设置封面图片
controller: this.videoController // 设置控制器
})
.width(300)
.height(210)
Row({space: 10}) {
Button("开始播放")
.onClick(() => {
this.videoController.start()
})
Button("暂停播放")
.onClick(() => {
this.videoController.pause()
})
Button("继续播放")
.onClick(() => {
this.videoController.start()
})
}
Row() {
Button("全屏播放")
.onClick(() => {
this.videoController.requestFullscreen(true)
})
Button("退出全屏")
.onClick(() => {
this.videoController.exitFullscreen()
})
}
}
.width("100%")
.height("100%")
}
}
样例运行结果如下图所示:
如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。