VideoContext.exitPictureInPicture(Object object)

以 Promise 风格 调用:不支持

微信小程序插件:支持

相关文档: video 组件

功能描述

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

参数

Object object

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

视频上下文

相关文档: video 组件

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

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

方法

VideoContext.play()

播放视频

VideoContext.pause()

暂停视频

VideoContext.stop()

停止视频

VideoContext.seek(number position)

跳转到指定位置

VideoContext.sendDanmu(Object data)

发送弹幕

VideoContext.playbackRate(number rate)

设置倍速播放

VideoContext.requestFullScreen(Object object)

进入全屏。如果有自定义内容需要在全屏时展示,需要把内容节点放到 video 节点里面。

VideoContext.exitFullScreen()

退出全屏

VideoContext.showStatusBar()

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

VideoContext.hideStatusBar()

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

VideoContext.exitPictureInPicture()

退出小窗,这个方法可以在任意页面调用

VideoContext.requestBackgroundPlayback()

进入后台小窗播放模式。

VideoContext.exitBackgroundPlayback()

退出后台小窗播放模式。

VideoContext.startCasting()

开始投屏,拉起半屏搜索设备。只支持在 tap 事件回调里调用。

VideoContext.switchCasting()

切换投屏设备。只支持在 tap 事件回调里调用。

VideoContext.reconnectCasting()

重连投屏设备。只支持在 tap 事件回调里调用。

VideoContext.exitCasting()

退出投屏。只支持在 tap 事件回调里调用。

示例代码

在开发者工具中预览效果

<view class="section tc">
  <video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" enable-danmu danmu-btn controls></video>
  <view class="btn-area">
    <input bindblur="bindInputBlur"/>
    <button bindtap="bindSendDanmu">发送弹幕</button>
  </view>
</view>
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()
    })
  }
})

wx.checkDeviceSupportHevc(Object object)

以 Promise 风格 调用:不支持

微信小程序插件:支持,需要微信小程序基础库版本不低于 3.8.11

功能描述

查询设备是否支持 H.265 编码

参数

Object object

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

object.success 回调函数

参数
Object res
属性 类型 说明
supportHevc Boolean 设备是否支持 H.265 编码

示例代码

wx.checkDeviceSupportHevc({
  success (res) {
    const supportHevc = res.supportHevc
  }
})

wx.chooseMedia(Object object)

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

以 Promise 风格 调用:支持

微信小程序插件:支持,需要微信小程序基础库版本不低于 2.11.1

微信 Windows 版:支持

微信 Mac 版:支持

微信 鸿蒙 OS 版:支持

功能描述

拍摄或从手机相册中选择图片或视频。

参数

Object object

属性 类型 默认值 必填 说明
count number 9 否 最多可以选择的文件个数,基础库2.25.0前,最多可支持9个文件,2.25.0及以后最多可支持20个文件
mediaType Array.<string> [‘image’, ‘video’] 否 文件类型
合法值 说明
image 只能拍摄图片或从相册选择图片
video 只能拍摄视频或从相册选择视频
mix 可同时选择图片和视频
sourceType Array.<string> [‘album’, ‘camera’] 否 图片和视频选择的来源
合法值 说明
album 从相册选择
camera 使用相机拍摄
maxDuration number 10 否 拍摄视频最长拍摄时间,单位秒。时间范围为 3s 至 60s 之间。不限制相册。
sizeType Array.<string> [‘original’, ‘compressed’] 否 是否压缩所选文件,基础库2.25.0前仅对 mediaType 为 image 时有效,2.25.0及以后对全量 mediaType 有效
camera string ‘back’ 否 仅在 sourceType 为 camera 时生效,使用前置或后置摄像头
合法值 说明
back 使用后置摄像头
front 使用前置摄像头
success function 否 接口调用成功的回调函数
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

参数
Object res
属性 类型 说明
tempFiles Array.<Object> 本地临时文件列表
结构属性 类型 说明
tempFilePath string 本地临时文件路径 (本地路径)
size number 本地临时文件大小,单位 B
duration number 视频的时间长度
height number 视频的高度
width number 视频的宽度
thumbTempFilePath string 视频缩略图临时文件路径
fileType string 文件类型
合法值 说明
image 图片
video 视频
type string 文件类型,有效值有 image 、video、mix

示例代码

wx.chooseMedia({
  count: 9,
  mediaType: ['image','video'],
  sourceType: ['album', 'camera'],
  maxDuration: 30,
  camera: 'back',
  success(res) {
    console.log(res.tempFiles[0].tempFilePath)
    console.log(res.tempFiles[0].size)
  }
})