微信小程式把玩(三十五)Video API
阿新 • • 發佈:2019-02-08
電腦端不能測試拍攝功能只能測試選擇視訊功能,好像只支援mp4格式,值得注意的是成功之後返回的臨時檔案路徑是個列表tempFilePaths而不是tempFilePath文件寫的有點問題。
主要屬性:
wx.chooseVideo(object)
成功之後返回引數
wxml
<button type="primary" bindtap="listenerBtnOpenVideo">開啟視訊</button>
<!--預設視訊元件是隱藏的-->
<video src="{{videoSource}}" hidden="{{videoHidden }}" style="width: 100%; height: 100%"/>
js
Page({
data:{
// text:"這是一個頁面"
videoSource: '',
videoHidden: true
},
listenerBtnOpenVideo: function() {
var that = this;
wx.chooseVideo({
//相機和相簿
sourceType: ['album', 'camera'],
//錄製視訊最大時長
maxDuration: 60 ,
//攝像頭
camera: ['front', 'back'],
//這裡返回的是tempFilePaths並不是tempFilePath
success: function(res){
console.log(res.tempFilePaths[0])
that.setData({
videoSource: res.tempFilePaths[0],
videoHidden: false
})
},
fail: function (e) {
console.log(e)
}
})
},
onLoad:function(options){
// 頁面初始化 options為頁面跳轉所帶來的引數
},
onReady:function(){
// 頁面渲染完成
},
onShow:function(){
// 頁面顯示
},
onHide:function(){
// 頁面隱藏
},
onUnload:function(){
// 頁面關閉
}
})