May 18, 2021 WeChat Mini Program Development Document
Base library 2.10.0 starts to be supported, and low versions need to be compatible.
Shoot or select a picture or video from your phone album.
Property | Type | The default | Required | Description |
---|---|---|---|---|
count | number | 9 | Whether | You can select up to a maximum number of files |
mediaType | Array.<string> | ['image', 'video'] | Whether | The file type |
sourceType | Array.<string> | ['album', 'camera'] | Whether | The source of the picture and video selection |
maxDuration | number | 10 | Whether | The maximum shooting time, in seconds. The time range is between 3s and 30s |
sizeType | Array.<string> | ['original', 'compressed'] | Whether | Whether to compress the selected file is valid only if mediaType is image |
camera | string | 'back' | Whether | Use a front or rear camera only when sourceType is camera |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
The legal value of object.mediaType
Value | Description | The lowest version |
---|---|---|
image | You can only take pictures or select pictures from an album | |
video | You can only shoot videos or select videos from albums |
The legal value of object.sourceType
Value | Description | The lowest version |
---|---|---|
album | Select from the album | |
camera | Shoot with the camera |
The legal value of object.camera
Value | Description | The lowest version |
---|---|---|
back | Use the rear camera | |
front | Use front camera |
Attributes | type | illustrate |
---|---|---|
tempFiles | Array.<Object> | Local temporary file list |
type | string | File type, valid values are image, video |
The structure of res.tempFiles
Property | Type | Description |
---|---|---|
tempFilePath | string | Local Temporary File Path (Local Path) |
size | number | Local temporary file size, unit B |
duration | number | The length of the video |
height | number | The height of the video |
width | number | The width of the video |
thumbTempFilePath | string | Video thumbnail temporary file path |
wx.chooseMedia({
count: 9,
mediaType: ['image','video'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success(res) {
console.log(res.tempFiles.tempFilePath)
console.log(res.tempFiles.size)
}
})