WeChat Open Platform

Mini Programs Documentation

Video

wx.chooseVideo(OBJECT)

Record a video or select a video from an album, returns temporary video file path.

OBJECT parameter descriptions:

Parameter Type Required Description
sourceType StringArray No album (video selected from album), camera (camera used to film video), defaults are: ['album', 'camera']
maxDuration Number No Maximum video recording time in seconds, a maximum duration of 60 seconds is supported
camera String No Default call for front or back camera. front: front, back: back, default back
success Function No Successful interface call, returns temporary video file path, refer to return parameter descriptions
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

success return parameter descriptions:

Parameter Description
tempFilePath Selected temporary video file path
duration Selected video duration
size Selected video data size
height Returns selected video length
width Returns selected video width

Note: Temporary file paths can be used as normal during this Mini Program startup. wx.saveFile needs to be called actively if files need to be saved permanently. They can only be accessed the next time the Mini Program is launched.

Sample code:

<view class="container">
    <video src="{{src}}"></video>
    <button bindtap="bindButtonTap">Get video</button>
</view>
Page({
    bindButtonTap: function() {
        var that = this
        wx.chooseVideo({
            sourceType: ['album','camera'],
            maxDuration: 60,
      camera: 'back',
            success: function(res) {
                that.setData({
                    src: res.tempFilePath
                })
            }
        })
    }
})

Bugs & Tips

  1. tip: Camera parameters are ineffective on some Android phones as they are not supported by system ROM.