zl程序教程

您现在的位置是:首页 >  工具

当前栏目

微信小程序 Video API

2023-09-27 14:29:06 时间

版权声明:本文为博主原创文章,未经博主允许不得转载。

这里写图片描述

电脑端不能测试拍摄功能只能测试选择视频功能,好像只支持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(){
    // 页面关闭
  }
})