@uni/video
v1.0.8
Published
[](https://www.npmjs.com/package/@uni/video)
Readme
chooseVideo
Takes a video or selects a video from the mobile album.
Supported
Install
$ npm install @uni/video --saveor
$ npm install @uni/apis --saveUsage
import { chooseVideo } from '@uni/video';
chooseVideo({
sourceType: ['album', 'camera'],
compressed: true,
camera: 'back',
maxDuration: 100,
success (res) {
console.log(res);
}
});
// promise
chooseVideo({
sourceType: ['camera'],
compressed: false,
camera: 'front',
maxDuration: 20,
}).then(res => {
console.log(res);
});
You can also import from the big package:
import { video } from '@uni/apis';
video.chooseVideo({
sourceType: ['album', 'camera'],
compressed: true,
camera: 'back',
maxDuration: 100,
success (res) {
console.log(res);
}
});
// promise
video.chooseVideo({
sourceType: ['camera'],
compressed: false,
camera: 'front',
maxDuration: 20,
}).then(res => {
console.log(res);
});
Methods
chooseVideo(options)
Arguments
| Property | Type | Description | required | Default |
| --- | --- | --- | --- | --- |
| options | object | | ✘ | - |
| options.sourceType | Array<string> | The source of the video | ✘ | ['album', 'camera'] |
| options.maxDuration | number | The maximum duration of a recorded video | ✘ | 60 |
| options.success | Function | The callback function for a successful API call | ✘ | - |
| options.fail | Function | The callback function for a failed API call | ✘ | - |
| options.complete | Function | The callback function used when the API call completed (always executed whether the call succeeds or fails) | ✘ | - |
Special Arguments
| Property | Type | Description | required | Default | Supported |
| --- | --- | --- | --- | --- | -- |
| options.camera | string | Indicates the default camera to be enabled. can be 'back' or 'front' | ✘ | 'back' | |
| options.compressed | boolean | Indicates whether to compress the selected video file | ✘ | true | |
Return
| Property | Type | Description |
| --- | --- | --- |
| tempFilePath | string | Temporary file path of the selected video |
| duration | number | Duration of the selected video |
| size | number | Amount of data of the selected video |
| width | number | Returns the height of the selected video |
| height | number | Returns the width of the selected video |
createVideoContext
Creates the VideoContext object for the video.
Supported
Install
$ npm install @uni/video --saveor
$ npm install @uni/apis --saveUsage
import { createVideoContext } from '@uni/video';
const videoContext = createVideoContext('videoId');
You can also import from the big package:
import { video } from '@uni/apis';
const videoContext = video.createVideoContext('videoId');
Methods
createVideoContext(id, context)
Arguments
| Property | Type | Description | required | Default |
| --- | --- | --- | --- | --- |
| id | string | The video components ID | ✔ | - |
| context | object | The this object of the current component instance in custom components. It is used with the video component(only for wechat and bytedance) | ✘ | - |
Return
| Property | Type | Description |
| --- | --- | --- |
| videoContext | VideoContext | VideoContext is bound to an video component with an id, to work with the video component. |
