tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-03-20 18:01:56
Video
Last updated: 2025-03-20 18:01:56

saveVideoToPhotosAlbum

This API is used via wx.saveVideoToPhotosAlbum(Object object).
Feature Description: Save video system album. Support mp4 video format.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
filePath
string
-
Yes
The path of the video file, which can either be a temporary file path or a permanent file path.
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Sample Code
wx.saveVideoToPhotosAlbum({
filePath: 'wxfile://xxx',
success(res) {
console.log(res.errMsg)
},
})

createVideoContext

This API is used via VideoContext wx.createVideoContext(string id, Object this).
Feature Description: Creates a VideoContext object.
Parameter and Description:
string id: The id of the <video> component.
"this" of the current component instance under custom components, used to operate the <video> component within.
Return Value: VideoContext

chooseVideo

This API is used via wx.chooseVideo(Object object).
Feature Description: Captures a video or selects a video from the phone's album.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
sourceType
Array.\\<string>
['album', 'camera']
No
Video Selection Source
compressed
boolean
true
No
Whether to compress the selected video file
maxDuration
number
60
No
Maximum recording time of video, in seconds.
camera
string
‘back’
No
The default is to activate the front or rear camera. However, on some Android phones, this may not work because the system ROM does not support this feature.
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Valid values of object.sourceType
Value
Description
album
Select video from the album
camera
Capture video using the camera
Valid values of object.camera
Value
Description
back
Default to activating the rear camera.
front
Default to activating the front camera.
Parameters for object.success callback function: Object res.
Attribute
Type
Description
tempFilePath
string
Temporary file path of the selected video.
duration
number
Duration of the selected video.
size
number
Data size of the selected video.
height
number
Return to selecting the height of the selected video.
width
number
Return to selecting the width of the selected video.
Sample Code
wx.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: 'back',
success(res) {
console.log(res.tempFilePath)
},
})

compressVideo

This API is used via wx.compressVideo(Object object).
Feature Description: Compressed video interface. The developer can specify the quality of the compression for compression. When finer control is needed, bitrate, fps, and resolution can be specified, which are ignored when quality is passed in.
Parameter and Description: Object.
Attribute
Type
Required
Description
src
string
Yes
The path of the video file, which can either be a temporary file path or a permanent file path.
quality
string
Yes
Compression quality, whose valid values are:
Low: Low power
Medium: Moderate power
High: High power
bitrate
number
Yes
Bitrate, measured in kbps.
fps
number
Yes
Frame rate
resolution
number
Yes
Resolution ratio relative to the original video, with the value range of (0, 1].
success
function
No
Callback Function of Successful Interface Call
fail
function
No
Callback Function of Failing Interface Call
complete
function
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Parameters for object.success callback function: Object res.
Attribute
Type
Description
tempFilePath
string
Address of the temporary file after compression.
size
string
Size after compression, measured in kB.

chooseMedia

This method is used via wx.chooseMedia(Object object).
Feature Description: Captures or selects images or videos from the mobile phone's album.
Parameter and Description: Object
Attribute
Type
Default value
Required
Description
count
number
9
No
Number of files that can be selected, supports up to 15 files
mediaType
Array.<string>
['image','video']
No
File type, whose valid values are:
Image: Only capture images or select images from the album.
Video: Only capture videos or select videos from the album.
sourceType
Array.<string>
['album', 'camera']
No
The source of image and video selection, whose valid values are:
Album: Select from album
Camera: Uses the camera for photographing
maxDuration
number
10
No
Maximum recording time for shooting video, in seconds. The time range is between 3s and 60s. There is no limit to albums.
sizeType
Array.<string>
['original', 'compressed']
No
Only available when mediaType is image, whether to compress the selected file or not.
camera
string
'back'
No
Only valid when sourceType is camera, use front or back camera, legal value is:
back: use rear camera
front: use front camera
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Parameters for object.success callback function: Object res.
Attribute
Type
Description
tempFiles
Array.<Object>
List of local temporary files
type
string
File type, whose valid values include image, video
Structure attribute of tempFiles
Structure attributes
Type
Description
tempFilePath
string
Local temporary file path (local direct)
size
number
Size of local temporary files, measured in bytes.
duration
number
Duration of video
height
number
Video height
width
number
Video width
fileType
string
File type, whose valid values are:
Image
Video
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)
}
})

VideoContext

Feature Description: VideoContext instance, which can be obtained through wx.createVideoContext. VideoContext is bound to a <video> component through its id, and operates the corresponding <video> component.
Sample Code
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">Dispatch the barrage</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(),
})
},
})


Method Set


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

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon