# wx.chooseMedia(Object object)

Start from base library version 2.10.0. Please remaining backward compatible.

with Promise style call: Supported

Mini Program plugin: Support, need to Mini Program base library version no less than 2.11.1

Take or select pictures or videos from your phone album.

# parameter

# Object object

attribute type Default values Required Introductions
count number 9 no Maximum number of files to choose from
mediaType Array.&ltstring&gt ['image', 'video'] no File Type
sourceType Array.&ltstring&gt ['album', 'camera'] no Source of pictures and videos selected
maxDuration number 10 no Maximum shooting time per second. The time frame is 3s to 60s Between. No album restrictions.
sizeType Array.&ltstring&gt ['original', 'compressed'] no Only mediaType for image Whether to compress the selected files
camera string 'back' no Only in sourceType for camera With front or rear camera
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Callback function at the end of an interface call (both successful and unsuccessful calls are executed)

object.mediaType Legal value

value Introductions Minimum version
image Only take pictures or select pictures from the album
video Only shoot video or select video from album

object.sourceType Legal value

value Introductions Minimum version
album Select from Album
camera Shooting with a camera

object.camera Legal value

value Introductions Minimum version
back Use a rear camera
front Use a front-facing camera

# object.success callback

# parameter
# Object res
attribute type Introductions
tempFiles Array.&ltObject&gt Local Temporary File List
type string File type, valid values are image 、video

res.tempFiles Structure

attribute type Introductions
tempFilePath string Local temporary file path (Local path)
size number Local temporary file size, unit B
duration number Length of video
height number Height of video
width number Width of video
thumbTempFilePath string Video thumbnail temporary file path

# sample code

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)
  }
})