微信小程序插件:支持
相关文档: video 组件
功能描述
播放视频
以 Promise 风格 调用:不支持
微信小程序插件:支持
相关文档: video 组件
退出小窗,该方法可在任意页面调用
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
相关文档: video 组件
VideoContext 实例,可通过 wx.createVideoContext 获取。
VideoContext 通过 id 跟一个 video 组件绑定,操作对应的 video 组件。
播放视频
暂停视频
停止视频
跳转到指定位置
发送弹幕
设置倍速播放
进入全屏。如果有自定义内容需要在全屏时展示,需要把内容节点放到 video 节点里面。
退出全屏
显示状态栏,只在 iOS 全屏下有效
隐藏状态栏,只在 iOS 全屏下有效
退出小窗,这个方法可以在任意页面调用
进入后台小窗播放模式。
退出后台小窗播放模式。
开始投屏,拉起半屏搜索设备。只支持在 tap 事件回调里调用。
切换投屏设备。只支持在 tap 事件回调里调用。
重连投屏设备。只支持在 tap 事件回调里调用。
退出投屏。只支持在 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()
})
}
})
以 Promise 风格 调用:不支持
微信小程序插件:支持,需要微信小程序基础库版本不低于 3.8.11
查询设备是否支持 H.265 编码
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
| 属性 | 类型 | 说明 |
|---|---|---|
| supportHevc | Boolean | 设备是否支持 H.265 编码 |
wx.checkDeviceSupportHevc({
success (res) {
const supportHevc = res.supportHevc
}
})
基础库 2.10.0 开始支持,低版本需做兼容处理。
以 Promise 风格 调用:支持
微信小程序插件:支持,需要微信小程序基础库版本不低于 2.11.1
微信 Windows 版:支持
微信 Mac 版:支持
微信 鸿蒙 OS 版:支持
拍摄或从手机相册中选择图片或视频。
| 属性 | 类型 | 默认值 | 必填 | 说明 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | number | 9 | 否 | 最多可以选择的文件个数,基础库2.25.0前,最多可支持9个文件,2.25.0及以后最多可支持20个文件 | |||||||||
| mediaType | Array.<string> | [‘image’, ‘video’] | 否 | 文件类型 | |||||||||
| |||||||||||||
| sourceType | Array.<string> | [‘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 时生效,使用前置或后置摄像头 | |||||||||
| |||||||||||||
| success | function | 否 | 接口调用成功的回调函数 | ||||||||||
| fail | function | 否 | 接口调用失败的回调函数 | ||||||||||
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | ||||||||||
| 属性 | 类型 | 说明 | |||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| tempFiles | Array.<Object> | 本地临时文件列表 | |||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
| 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)
}
})