成都创新互联网站制作重庆分公司

创新互联小程序教程:微信小程序API视频·VideoContext

VideoContext

VideoContext 实例,可通过 wx.createVideoContext 获取。

VideoContext 通过 id 跟一个 video 组件绑定,操作对应的 video 组件。

方法:

VideoContext.exitFullScreen()

基础库 1.4.0 开始支持,低版本需做兼容处理。

退出全屏

VideoContext.exitPictureInPicture(Object object)

退出小窗,该方法可在任意页面调用

参数

Object object

属性 类型 默认值 必填 说明
success function 否 接口调用成功的回调函数
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数(调用成功、失败都会执行)

VideoContext.hideStatusBar()

基础库 2.1.0 开始支持,低版本需做兼容处理。

隐藏状态栏,仅在iOS全屏下有效

VideoContext.pause()

暂停视频

VideoContext.play()

播放视频

VideoContext.playbackRate(number rate)

基础库 1.4.0 开始支持,低版本需做兼容处理。

设置倍速播放

参数

number rate

倍率,支持 0.5/0.8/1.0/1.25/1.5,2.6.3 起支持 2.0 倍速

VideoContext.requestFullScreen(Object object)

基础库 1.4.0 开始支持,低版本需做兼容处理。

进入全屏。若有自定义内容需在全屏时展示,需将内容节点放置到 video 节点内。

参数

Object object

属性 类型 默认值 必填 说明 最低版本
direction number 否 设置全屏时视频的方向,不指定则根据宽高比自动判断。 1.7.0

object.direction 的合法值

值 说明 最低版本
0 正常竖向
90 屏幕逆时针90度
-90 屏幕顺时针90度

VideoContext.seek(number position)

跳转到指定位置

参数

number position

跳转到的位置,单位 s

VideoContext.sendDanmu(Object data)

发送弹幕

参数

Object data

弹幕内容

属性 类型 默认值 必填 说明
text string 是 弹幕文字
color string 否 弹幕颜色

VideoContext.showStatusBar()

基础库 2.1.0 开始支持,低版本需做兼容处理。

显示状态栏,仅在iOS全屏下有效

VideoContext.stop()

基础库 1.7.0 开始支持,低版本需做兼容处理。

停止视频

示例代码

在开发者工具中预览效果


  
  
    
    
  

function getRandomColor () {
  let 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('')
}

Page({
  onReady (res) {
    this.videoContext = wx.createVideoContext('myVideo')
  },
  inputValue: '',
  bindInputBlur (e) {
    this.inputValue = e.detail.value
  },
  bindSendDanmu () {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  }
})

分享题目:创新互联小程序教程:微信小程序API视频·VideoContext
标题路径:http://cxhlcq.cn/article/cdiccjo.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部