中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
继承VideoController后,再调用VideoController中的方法不再生效;现象就是点击暂停,暂停不下来,debug和日志可以看到方法已经被调用
微信扫码分享
// xxx.ets @Entry @Component struct VideoCreateComponent { @State videoSrc: Resource = $rawfile('video1.mp4') @State previewUri: Resource = $r('app.media.APEX') @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X @State isAutoPlay: boolean = false @State showControls: boolean = true controller: myVideoCol = new myVideoCol(); build() { Column() { Video({ src: this.videoSrc, previewUri: this.previewUri, currentProgressRate: this.curRate, controller: this.controller }) .width('100%') .height(600) .autoPlay(this.isAutoPlay) .controls(this.showControls) .onStart(() => { console.info('onStart') }) .onPause(() => { console.info('onPause') }) .onUpdate((e?: TimeObject) => { if (e != undefined) { console.info('onUpdate is ' + e.time) } }) Row() { Button('start').onClick(() => { this.controller.myStart() // 开始播放 }).margin(5) Button('pause').onClick(() => { this.controller.pause() // 暂停播放 }).margin(5) Button('stop').onClick(() => { this.controller.myStop() // 结束播放 }).margin(5) Button('setTime').onClick(() => { this.controller.mySeekTo(10) // 精准跳转到视频的10s位置 // this.controller.setCurrentTime(10, SeekMode.Accurate) // 精准跳转到视频的10s位置 }).margin(5) } } } } interface DurationObject { duration: number; } interface TimeObject { time: number; } class myVideoCol extends VideoController { myStart(): void { console.log("myVideoCol === myStart") super.start() } pause(): void { console.log("myVideoCol === myPause") super.pause() } myStop(): void { console.log("myVideoCol === myStop") super.stop() } mySeekTo(time: number): void { console.log("myVideoCol === mySeekTo") super.setCurrentTime(time) } }