VideoContext 实例,可通过 wx.createVideoContext 获取。
VideoContext 通过 id 跟一个 video 组件绑定,操作对应的 video 组件。
播放视频
暂停视频
停止视频
跳转到指定位置
number position 跳转到的位置,单位 s
// 创建 VideoContext 实例
const videoContext = xhs.createVideoContext('myVideo'); // 'myVideo' 是 video 组件的 id
// 播放视频
videoContext.play({
success: () => {
console.log('视频播放成功');
},
fail: (err) => {
console.error('视频播放失败:', err.errMsg);
}
});
// 暂停视频
videoContext.pause({
success: () => {
console.log('视频暂停成功');
},
fail: (err) => {
console.error('视频暂停失败:', err.errMsg);
}
});
// 停止视频
videoContext.stop({
success: () => {
console.log('视频停止成功');
},
fail: (err) => {
console.error('视频停止失败:', err.errMsg);
}
});
// 跳转到指定时间(单位:秒)
videoContext.seek({
position: 15, // 跳转到 15 秒
success: () => {
console.log('跳转成功');
},
fail: (err) => {
console.error('跳转失败:', err.errMsg);
}
});