微信小程序把玩(三十五)Video API

這裏寫圖片描述

電腦端不能測試拍攝功能只能測試選擇視頻功能,好像只支持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(){
    // 頁面關閉
  }
})
發佈了154 篇原創文章 · 獲贊 173 · 訪問量 132萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章