HomeDocs
跳到主要内容

VideoContext

简介​

VideoContext 实例,可通过dlt.createVideoContext 获取。
VideoContext 通过 id 跟一个 native-video 组件或者 video 绑定,操作对应的 native-video 组件或者 video 组件。

使用限制​

操作 native-video 组件的 VideoContext 实例方法最低基础库版本号为 4.0.0,请注意兼容
操作 video 组件的 VideoContext 实例方法最低基础库版本号为 5.1.1,请注意兼容

方法​

VideoContext.play()
播放视频

VideoContext.pause()
暂停视频

VideoContext.stop()
停止视频

VideoContext.seek(number position)
跳转到指定位置

VideoContext.playAndseek(number position)
跳转到指定位置,并且播放

VideoContext.requestFullScreen(Object object)
进入全屏

VideoContext.exitFullScreen(Object object)
退出全屏

示例代码​

<!--index.dlt-->
<native-video :src="src" id="myVideo"></native-video>

<view bind:tap="triggerPlay"> 点击播放 </view>
<view bind:tap="triggerPause"> 点击暂停 </view>
<view bind:tap="triggerStop"> 点击停止 </view>
<view bind:tap="triggerFullscreen"> 点击全屏 </view>
<view bind:tap="triggerSeek"> 跳转到指定位置 </view>
// index.js
Page({
data: {
src: 'xxxx.mp4',
},
onLoad() {
this.videoContext = dlt.createVideoContext('myVideo');
},
// 通过 videoContext 调用视频方法
triggerPlay() {
this.videoContext && this.videoContext.play();
},
triggerPause() {
this.videoContext && this.videoContext.pause();
},
triggerStop() {
this.videoContext && this.videoContext.stop();
},
triggerFullscreen() {
this.videoContext && this.videoContext.requestFullScreen({ direction: 0 });

// 模拟五秒后退出全屏
setTimeout(() => {
this.videoContext && this.videoContext.exitFullScreen();
}, 5000);
},
triggerSeek() {
// 设置播放进度到 10 秒位置处
this.videoContext && this.videoContext.seek(10);
},
});
Privacy agreementDeveloper agreementcontact us: developer_private.mi@dlightek.com © 2024 MiniApp. All Rights Reserved.