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.
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');
}
});
The incoming parameter is of the Object type with the following properties:
| Property | Data type | Required | Description |
|---|---|---|---|
sourceType | Array<String> | No | Indicates 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']. |
compressed | Boolean | No | Specifies 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. |
maxDuration | Number | No | Indicates 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. |
camera | String | No | Indicates 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. |
success | Function | No | The callback function to be executed when the request is successful. |
fail | Function | No | The callback function to be executed when the request is failed. |
complete | Function | No | The callback function to be executed when the request is completed (to be executed whether the request is successful or failed). |
The following table provides the properties in the success callback function:
| Property | Type | Description |
|---|---|---|
tempFilePath | String | Indicates the temporary file path of the selected video. |
duration | Number | Indicates the length of the selected video. |
size | Number | Indicates the size of the selected video. |
height | Number | Indicates the height of the selected video. |
width | Number | Indicates the width of the selected video. |
The following table provides the possible error codes and messages in the API call:
| Error code | Error message | Solution |
|---|---|---|
2 | Invalid parameters. | Check the values in your request and provide correct parameters. |
3 | An unknown error occurs. | Check whether the calling process is normal. If not resolved, contact our technical support to troubleshoot this issue. |
11 | The operation was canceled by the user. | Normal user interaction and no further processing is required. |
12 | An error occurs in data processing. | Call the API again. |
13 | The file size exceeds the limit. | Check whether you have enough RAM. |
14 | No access to camera. | Check app permissions for camera. |
15 | No access to album. | Check app permissions for album. |
sourceType parameter controls whether to use camera, album, or bothcompressed settingcamera parameter may not work on some Android devices due to ROM limitationsmaxDuration parameter only applies when shooting a new video, not when selecting from album