視頻 API
createVideoContext?
ty.createVideoContext(string id)
創(chuàng)建?video?上下文?VideoContext?對象。
參數(shù)
string id
video?組件的 id
返回值
VideoContext
VideoContext
VideoContext 實例,可通過?ty.createVideoContext?獲取。
VideoContext 通過 id 跟一個?video?組件綁定,操作對應(yīng)的?video?組件。
方法
VideoContext.play
VideoContext.play()
播放視頻
VideoContext.pause
VideoContext.pause()
暫停視頻
VideoContext.stop
VideoContext.stop()
停止視頻
VideoContext.playbackRate
VideoContext.playbackRate(number rate)
設(shè)置倍速播放
VideoContext.seek
VideoContext.seek(number position)
跳轉(zhuǎn)到指定位置
參數(shù)
number position
跳轉(zhuǎn)到的位置,單位 s
VideoContext.sendDanmu
VideoContext.sendDanmu(Object data)
發(fā)送彈幕
參數(shù)
Object data
彈幕內(nèi)容
屬性 | 類型 | 默認值 | 必填 | 說明 |
---|---|---|---|---|
text | string | 是 | 彈幕文字 | |
color | string | 否 | 彈幕顏色 |
???立即開發(fā)。文章來源地址http://www.zghlxwxcb.cn/news/detail-844260.html
原生視頻 API
createNativeVideoContext??
ty.createNativeVideoContext(string id)
創(chuàng)建?native-video?上下文?NativeVideoContext?對象。
參數(shù)
string id
native-video?組件的 id
返回值
NativeVideoContext
NativeVideoContext
VideoContext 實例,可通過?ty.createNativeVideoContext?獲取。
NativeVideoContext 通過 id 跟一個?native-video?組件綁定,操作對應(yīng)的?native-video?組件。
方法
NativeVideoContext.play
NativeVideoContext.play()
播放視頻
NativeVideoContext.pause
NativeVideoContext.pause()
暫停視頻
NativeVideoContext.stop
NativeVideoContext.stop()
停止視頻
NativeVideoContext.playbackRate
NativeVideoContext.playbackRate(number rate)
設(shè)置倍速播放?
NativeVideoContext.seek
NativeVideoContext.seek(number position)
跳轉(zhuǎn)到指定位置
參數(shù)
number position
跳轉(zhuǎn)到的位置,單位 s
???立即開發(fā)。
WebView API
WebviewContext
WebviewContext 實例,可通過?ty.createWebviewContext?獲取。
基礎(chǔ)庫 >= 2.15.0
interface WebviewContext {
postMessage(msg: { data: Record<string, any>}): void;
reload(options?: {
success?: () => void;
fail?: () => void;
complete?: () => void;
}): void;
}
方法
postMessage
發(fā)送數(shù)據(jù)到 web-view 頁面中,頁面內(nèi)通過?@tuya-miniapp/jssdk?進行接收。
reload
刷新當(dāng)前 web-view 頁面。
ty.createWebviewContext(mapId: string)
用于創(chuàng)建 WebviewContext 實例
示例
<web-view id="w1" src="https://your-domain.com"></web-view>
Page({
onReady() {
this.webviewContext = ty.createWebviewContext('w1');
},
sendMessage() {
this.webviewContext.postMessage({
data: {
msg: 'send to html ' + Date.now(),
},
});
}
})
WebviewContext.postMessage
發(fā)送消息到 web-view 標簽的頁面中。
type postMessage = (msg: { data: Record<string, any>}) => void;
const webviewContext = ty.createWebviewContext('id')
webviewContext.postMessage({
data: {a: 1}
})
在 web-view 的 頁面中,需要通過?@tuya-miniapp/jssdk?進行消息的接收
import { miniProgram } from '@tuya-miniapp/jssdk'
miniProgram.onMessage(event => {
const messageData = event.data
// messageData => {a: 1}
})
WebviewContext.reload
刷新當(dāng)前 web-view 頁面
type reload = (options?: {
success?: () => void;
fail?: () => void;
complete?: () => void;
}) => void;
const webviewContext = ty.createWebviewContext('id')
webviewContext.reload()
???立即開發(fā)。
相機API?
createCameraContext?
ty.createCameraContext()
基礎(chǔ)庫 2.2.0 開始支持, 低版本需做兼容處理。
創(chuàng)建?camera?上下文?CameraContext?對象。
返回值
CameraContext
CameraContext
CameraContext 實例,可通過?ty.createCameraContext?獲取。
CameraContext 與頁面內(nèi)唯一的?camera?組件綁定,操作對應(yīng)的?camera?組件。
方法
CameraContext.takePhoto
拍攝照片
CameraContext.setZoom
設(shè)置縮放級別文章來源:http://www.zghlxwxcb.cn/news/detail-844260.html
takePhoto
CameraContext.takePhoto(Object object)
基礎(chǔ)庫 2.2.0 開始支持, 低版本需做兼容處理。
功能描述
拍攝照片
參數(shù)
Object Object
屬性 | 類型 | 默認值 | 必填 | 說明 |
---|---|---|---|---|
quality | string | normal | 否 | 成像質(zhì)量,可選值有?high : 高質(zhì)量,normal : 普通質(zhì)量,low : 低質(zhì)量 |
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í)行) |
object.success 回調(diào)函數(shù)
參數(shù)
Object res
屬性 | 類型 | 說明 |
---|---|---|
tempImagePath | string | 照片文件的臨時路徑 (本地路徑) |
setZoom
CameraContext.setZoom(Object object)
基礎(chǔ)庫 2.2.0 開始支持, 低版本需做兼容處理。
功能描述
設(shè)置縮放級別
參數(shù)
Object Object
屬性 | 類型 | 默認值 | 必填 | 說明 |
---|---|---|---|---|
zoom | number | 是 | 縮放級別,范圍[1, maxZoom]。zoom 可取小數(shù),精確到小數(shù)后一位。maxZoom 可在 bindinitdone 返回值中獲取。 | |
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í)行) |
object.success 回調(diào)函數(shù)
參數(shù)
Object res
屬性 | 類型 | 說明 |
---|---|---|
zoom | number | 實際設(shè)置的縮放級別。由于系統(tǒng)限制,某些機型可能無法設(shè)置成指定值,會改用最接近的可設(shè)值。 |
???立即開發(fā)。
到了這里,關(guān)于【小程序】媒體API能力集成指南——視頻、原生視頻、WebView、相機API的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!