tencent cloud

Last updated: 2025-09-30 14:47:57
Video
Last updated: 2025-09-30 14:47:57

saveVideoToPhotosAlbum

This API is called using wx.saveVideoToPhotosAlbum(Object object).
Feature description:Saves a video to the system album. Supported video format: MP4.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
filePath
string
-
True
The video file path, which can be a temporary file path or a permanent file path.
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example
wx.saveVideoToPhotosAlbum({
filePath: 'wxfile://xxx',
success(res) {
console.log(res.errMsg)
},
})

createVideoContext

This API is called using VideoContext wx.createVideoContext(string id, Object this).
Feature description:Creates a  VideoContext  object.
Parameter and description:
string id: The ID of the <video> component.
In the context of a custom component, this refers to the current component instance, allowing you to manipulate the  <video>  component within it.
Return value:VideoContext

chooseVideo

This API is called using wx.chooseVideo(Object object).
Feature description:Records a video or selects a video from the phone's album.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
sourceType
Array.<string>
['album', 'camera']
False
The source options for video selection.
compressed
Boolean
true
False
Whether to compress the selected video file.
maxDuration
number
60
False
Maximum recording time for the video, in seconds.
camera
string
'back'
False
Default camera to open (front or rear). May not work on some Android devices due to system ROM limitations.
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Valid values for object.sourceType
Value
Description
album
Selects a video from the album.
camera
Records a video using the camera.
Valid values for object.camera
Value
Description
back
Opens the rear camera by default.
front
Opens the front camera by default.
object.success callback function parameter:Object res.
Property
Type
Description
tempFilePath
string
The temporary file path of the selected video.
duration
number
The selected video duration in seconds.
size
number
The size of the selected video file, in bytes.
height
number
The height of the selected video.
width
number
The width of the selected video.
Example
wx.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: 'back',
success(res) {
console.log(res.tempFilePath)
},
})

compressVideo

This API is called using wx.compressVideo(Object object).
Feature description:Compresses a video file. Developers can specify compression quality using  quality . For more precise control, you can also specify  bitrate, fps, and  resolution.If  quality  is provided, these three parameters will be ignored.
Parameter and description:Object object.
Property
Type
‍Required
Description
src
string
True
The video file path, which can be a temporary file path or a permanent file path.
quality
string
True
Compression quality. Valid values:
low: Low
medium: Medium
high: High
bitrate
number
True
Bitrate in kbps.
fps
number
True
Frame rate.
resolution.
number
True
The resolution ratio relative to the original video. Value range: (0, 1].
success
function
False
Callback function for successful API calls.
fail
function
False
Callback function for failed API calls.
complete
function
False
Callback function executed after API call ends (regardless of success or failure).
object.success callback function parameter:Object res
Property
Type
Description
tempFilePath
string
The temporary file path of the compressed video.
size
string
The size of the compressed video, in KB.

chooseMedia

This API is called using wx.chooseMedia(Object object).
Feature description:Takes or selects images or videos from the phone's album.
Parameter and description:Object object
Property
Type
Default value
‍Required
Description
count
number
15
False
Maximum number of files that can be selected, up to 15 files.
mediaType
Array.<string>
['image','video']
False
File type. Valid values:
image: Only allows taking photos or selecting photos from the album
video: Only allows recording videos or selecting videos from the album
Note:
On iOS, any image format supported by the system photo app can be selected. Typically including JPG, PNG, HEIC (depending on device model and iOS version), and GIF.
sourceType
Array.<string>
['album', 'camera']
False
Source for selecting images and videos. Valid values:
album: Selects from the album
camera: Takes/records using the camera
maxDuration
number
10
False
Maximum recording time for videos, in seconds. The time range is between 3s and 60s. Videos selected from the album have no duration limit.
sizeType
Array.<string>
['original', 'compressed']
False
Effective only when mediaType is image. Indicates whether to compress the selected files.
camera
string
'back'
False
Effective only when sourceType is camera. Specifies whether to use the front or rear camera.
back: Uses the rear camera
front: Uses the front camera
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
object.success callback function parameter:Object res
Property
Type
Description
tempFiles
Array.<Object>
List of local temporary files.
type
string
File type. Valid values: image, video.
tempFiles structural property
Structural property
Type
Description
tempFilePath
string
Local temporary file path (local directory).
size
number
Size of the local temporary file in bytes.
duration
number
Video duration.
height
number
Video height.
width
number
Video width.
thumbTempFilePath
string
Temporary file path for video thumbnail.
fileType
string
File type. Valid values:
image: Image
video: Video
Example
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)
}
})

VideoContext

Feature description:A VideoContext instance that can be obtained using wx.createVideoContext . The videoContext is bound to a <video> component via its ID, allowing you to manipulate the corresponding <video> component.
Example
Corresponding WXML file:
<view class="section tc">
<video
id="myVideo"
src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400"
enable-danmu
danmu-btn
controls
></video>
<view class="btn-area">
<input bindblur="bindInputBlur" />
<button bindtap="bindSendDanmu">Send on-screen comments</button>
</view>
</view>
Corresponding js file:
function getRandomColor() {
const rgb = []
for (let i = 0; i < 3; ++i) {
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}

Page({
onReady(res) {
this.videoContext = wx.createVideoContext('myVideo')
},
inputValue: '',
bindInputBlur(e) {
this.inputValue = e.detail.value
},
bindSendDanmu() {
this.videoContext.sendDanmu({
text: this.inputValue,
color: getRandomColor(),
})
},
})

Methods



Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback