方法 | 参数 | 说明 |
---|
play | 无 | 播放 |
pause | 无 | 暂停 |
seek | position | 跳转到指定位置,单位 s |
stop | | 停止视频,仅微信小程序平台 支持, |
sendDanmu | danmu | 发送弹幕,danmu 包含两个属性 text, color |
playbackRate | rate | 设置倍速播放,支持的倍率有 0.5/0.8/1.0/1.25/1.5 |
requestFullScreen | 无 | 进入全屏,可传入{direction}参数,详见 video 组件文档 |
exitFullScreen | 无 | 退出全屏 |
showStatusBar | 无 | 显示状态栏,仅在iOS全屏下有效 |
hideStatusBar | 无 | 隐藏状态栏,仅在iOS全屏下有效 |
export default {
data() {
return {
title: 'video',
src: '',
inputValue: '',
danmuList: [{
text: '第 1s 出现的弹幕',
color: '#ff0000',
time: 1
},
{
text: '第 3s 出现的弹幕',
color: '#ff00ff',
time: 3
}
]
}
onReady: function (res) {
this.videoContext = uni.createVideoContext('myVideo')
},
methods: {
bindInputBlur: function (e) {
this.inputValue = e.target.value
},
bindButtonTap: function () {
var that = this
uni.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: ['front', 'back'],
success: function (res) {
this.src = res.tempFilePath
}
})
},
text: this.inputValue,
color: this.getRandomColor()
})
},
videoErrorCallback: function (e) {
console.log('视频错误信息:')
console.log(e.target.errMsg)
},
getRandomColor: function () {
const rgb = []
for (let i = 0; i < 3; ++i) {
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
}