新聞中心
VideoContext
VideoContext 實例,可通過 wx.createVideoContext 獲取。

VideoContext 通過 id 跟一個 video 組件綁定,操作對應(yīng)的 video 組件。
方法:
VideoContext.exitFullScreen()
基礎(chǔ)庫 1.4.0 開始支持,低版本需做兼容處理。
退出全屏
VideoContext.exitPictureInPicture(Object object)
退出小窗,該方法可在任意頁面調(diào)用
參數(shù)
Object object
| 屬性 | 類型 | 默認值 | 必填 | 說明 |
|---|---|---|---|---|
| success | function | 否 | 接口調(diào)用成功的回調(diào)函數(shù) | |
| fail | function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) | |
| complete | function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行) |
VideoContext.hideStatusBar()
基礎(chǔ)庫 2.1.0 開始支持,低版本需做兼容處理。
隱藏狀態(tài)欄,僅在iOS全屏下有效
VideoContext.pause()
暫停視頻
VideoContext.play()
播放視頻
VideoContext.playbackRate(number rate)
基礎(chǔ)庫 1.4.0 開始支持,低版本需做兼容處理。
設(shè)置倍速播放
參數(shù)
number rate
倍率,支持 0.5/0.8/1.0/1.25/1.5,2.6.3 起支持 2.0 倍速
VideoContext.requestFullScreen(Object object)
基礎(chǔ)庫 1.4.0 開始支持,低版本需做兼容處理。
進入全屏。若有自定義內(nèi)容需在全屏?xí)r展示,需將內(nèi)容節(jié)點放置到 video 節(jié)點內(nèi)。
參數(shù)
Object object
| 屬性 | 類型 | 默認值 | 必填 | 說明 | 最低版本 |
|---|---|---|---|---|---|
| direction | number | 否 | 設(shè)置全屏?xí)r視頻的方向,不指定則根據(jù)寬高比自動判斷。 | 1.7.0 |
object.direction 的合法值
| 值 | 說明 | 最低版本 |
|---|---|---|
| 0 | 正常豎向 | |
| 90 | 屏幕逆時針90度 | |
| -90 | 屏幕順時針90度 |
VideoContext.seek(number position)
跳轉(zhuǎn)到指定位置
參數(shù)
number position
跳轉(zhuǎn)到的位置,單位 s
VideoContext.sendDanmu(Object data)
發(fā)送彈幕
參數(shù)
Object data
彈幕內(nèi)容
| 屬性 | 類型 | 默認值 | 必填 | 說明 |
|---|---|---|---|---|
| text | string | 是 | 彈幕文字 | |
| color | string | 否 | 彈幕顏色 |
VideoContext.showStatusBar()
基礎(chǔ)庫 2.1.0 開始支持,低版本需做兼容處理。
顯示狀態(tài)欄,僅在iOS全屏下有效
VideoContext.stop()
基礎(chǔ)庫 1.7.0 開始支持,低版本需做兼容處理。
停止視頻
示例代碼
在開發(fā)者工具中預(yù)覽效果
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()
})
}
}) 本文標題:創(chuàng)新互聯(lián)小程序教程:微信小程序API視頻·VideoContext
URL標題:http://m.fisionsoft.com.cn/article/cdiccjo.html


咨詢
建站咨詢
