Media APIs

chooseVideo

Shoot a video or choose a video from the album.

Overview

my.chooseVideo allows users to shoot a video with the camera or choose a video from the device album. The API returns information about the selected video including its path, duration, size, and dimensions.

Sample Code

my.chooseVideo({
  sourceType: ['album', 'camera'],
  maxDuration: 60,
  camera: 'back',
  success: (res) => {
    console.log(res);
  },
  fail: (error) => {
    console.log(error);
  },
  complete: () => {
    console.log('The callback function to be executed whether the request is successful or fail');
  }
});

Parameters

The incoming parameter is of the Object type with the following properties:

PropertyData typeRequiredDescription
sourceTypeArray<String>NoIndicates the sources of the video.

Valid values are:
album: Choose a video from the album on a mobile device.
camera: Shoot a video with the camera on a mobile device.

By default, the value is ['album','camera'].
compressedBooleanNoSpecifies whether to compress the selected video file. For iOS, the video file is always compressed.

By default, the value is true, which means the selected video file is compressed.
maxDurationNumberNoIndicates the maximum amount of time to shoot a video, in seconds.

By default, the value is 60, which means the maximum amount of time is 60 seconds.
cameraStringNoIndicates which camera (front or back camera) is opened when launching the camera app.

For some Android devices, this configuration is not supported by the system ROM and thus cannot take effect.

Valid values are:
back: The back camera is opened.
front: The front camera is opened.

By default, the value is back.
successFunctionNoThe callback function to be executed when the request is successful.
failFunctionNoThe callback function to be executed when the request is failed.
completeFunctionNoThe callback function to be executed when the request is completed (to be executed whether the request is successful or failed).

Success Callback Function

The following table provides the properties in the success callback function:

PropertyTypeDescription
tempFilePathStringIndicates the temporary file path of the selected video.
durationNumberIndicates the length of the selected video.
sizeNumberIndicates the size of the selected video.
heightNumberIndicates the height of the selected video.
widthNumberIndicates the width of the selected video.

Error Codes

The following table provides the possible error codes and messages in the API call:

Error codeError messageSolution
2Invalid parameters.Check the values in your request and provide correct parameters.
3An unknown error occurs.Check whether the calling process is normal. If not resolved, contact our technical support to troubleshoot this issue.
11The operation was canceled by the user.Normal user interaction and no further processing is required.
12An error occurs in data processing.Call the API again.
13The file size exceeds the limit.Check whether you have enough RAM.
14No access to camera.Check app permissions for camera.
15No access to album.Check app permissions for album.

Usage Notes

  • The sourceType parameter controls whether to use camera, album, or both
  • For iOS devices, videos are always compressed regardless of the compressed setting
  • The camera parameter may not work on some Android devices due to ROM limitations
  • The maxDuration parameter only applies when shooting a new video, not when selecting from album