Attribute | Type | Default value | Description |
src | string | - | Image resource address, supporting cloud file ID (from version 2.2.3 onwards) |
mode | string | 'scaleToFill' | Image cropping and scaling mode |
lazy-load | boolean | false | Image lazy loading. This is only effective for images under 'page' and 'scroll-view'. |
binderror | handleevent | - | In the event of an error, the event name is published to the AppService, with the event object event.detail = {errMsg: 'something wrong'}. |
bindload | handleevent | - | Upon the completion of image loading, the event name is published to the AppService, with the event object event.detail = {height:'image height in px', width:'image width in px'}. |
aria-lable | string | - | Accessibility, (Attribute) Additional description of the element. |
Mode | Value | Description |
Scaling | scaleToFill | Scale the image without maintaining the aspect ratio, stretching the width and height of the image to completely fill the image element. |
Scaling | aspectFit | Scale the image while maintaining the aspect ratio, ensuring the longer side of the image is fully displayed. This allows the image to be shown in its entirety. |
Scaling | aspectFill | Scale the image while preserving the aspect ratio, ensuring only the shorter side of the image is fully displayed. This typically results in the image being complete in either the horizontal or vertical direction, with the other direction being cropped. |
Scaling | widthFix | Maintain the width constant while the height adjusts automatically, preserving the original aspect ratio of the image. |
Cropping | top | Only display the top region of the image without scaling the image. |
Cropping | bottom | Only display the bottom region of the image without scaling the image. |
Cropping | center | Only display the central region of the image without scaling the image. |
Cropping | left | Only display the left region of the image without scaling the image. |
Cropping | right | Only display the right region of the image without scaling the image. |
Cropping | top left | Only display the top left corner region of the image without scaling the image. |
Cropping | top right | Only display the top right region of the image without scaling the image. |
Cropping | bottom left | Only display the bottom left region of the image without scaling the image. |
Cropping | bottom right | Only display the bottom right region of the image without scaling the image. |
<view class="page"><view class="page__hd"><text class="page__title">image</text><text class="page__desc">Image</text></view><view class="page__bd"><view class="section section_gap" wx.for="{{array}}" wx.for-item="item"><view class="section__title">{{item.text}}</view><view class="section__ctn"><imagestyle="width: 200px; height: 200px; background-color: #eeeeee;"mode="{{item.mode}}"src="{{src}}"></image></view></view></view></view>
Page({data: {array: [{mode: 'scaleToFill',text: 'scaleToFill: Do not maintain aspect ratio when scaling the image, ensuring the image fully adapts.'}, {mode: 'aspectFit',text: 'aspectFit: Maintain aspect ratio when scaling the image, ensuring the image's longer side is fully displayed.'}, {mode: 'aspectFill',text: 'aspectFill: Maintain aspect ratio when scaling the image, ensuring the image's shorter side is fully displayed.'}, {mode: 'top',text: 'top: Only display the top region of the image without scaling the image.'}, {mode: 'bottom',text: 'bottom: Only display the bottom region of the image without scaling the image.'}, {mode: 'center',text: 'center: Only display the central region of the image without scaling the image.'}, {mode: 'left',text: 'left: Only display the left region of the image without scaling the image.'}, {mode: 'right',text: 'right: Only display the right region of the image without scaling the image.'}, {mode: 'top left',text: 'top left: Only display the top left region of the image without scaling the image.'}, {mode: 'top right',text: 'top right: Only display the top right region of the image without scaling the image.'}, {mode: 'bottom left',text: 'bottom left: Only display the bottom left region of the image without scaling the image.'}, {mode: 'bottom right',text: 'bottom right: Only display the bottom right region of the image without scaling the image.'}],src: '../resources/cat.jpg'},imageError(e) {console.log('Error event occurring in image3, carrying the value', e.detail.errMsg)}})
Attribute | Type | Default value | Description |
src | string | - | The resource address for playing the video, supporting cloud file ID. |
duration | number | - | Specify the video duration |
controls | boolean | true | Whether to display the default playback controls (play/pause button, playback progress, time) |
danmu-list | Object Array | - | Barrage list |
danmu-btn | boolean | false | Whether to display the barrage button, which is effective only at initialization and cannot be dynamically changed. |
enable-danmu | boolean | false | Whether to display the barrage, which is effective only at initialization and cannot be dynamically changed. |
autoplay | boolean | false | Whether to enable auto-play |
loop | boolean | false | Whether to enable loop playback |
muted | boolean | false | Whether to play in mute |
initial-time | number | - | Specify the initial playback position of the video. |
page-gesture | boolean | false | Whether to enable brightness and volume adjustment gestures in non-full screen mode. |
direction | number | - | Sets the orientation of the video in full screen mode. If not specified, it will be automatically determined based on the aspect ratio. The valid value is 0 (normal vertical orientation). The valid value is 90 (screen rotated 90 degrees counterclockwise). The valid value is -90 (screen rotated 90 degrees clockwise). |
show-progress | boolean | true | If not set, it will only display when the width exceeds 240. |
show-fullscreen-btn | boolean | true | Whether to display the full-screen button. |
show-play-btn | boolean | true | Whether to display the play button on the bottom control bar of the video. |
show-center-play-btn | boolean | true | Whether to display the play button in the middle of the video. |
enable-progress-gesture | boolean | true | Whether to activate the gesture control for progress. |
object-fit | string | contain | The video's display mode when the video size is inconsistent with the video container size. Contain: To encompass or include. Fill: To populate or saturate. Cover: To overlay or envelop. |
poster | string | - | The online resource address or cloud file ID for the video cover image. If the controls attribute value is false, then the poster setting is invalid. |
show-mute-btn | boolean | false | Whether to display the mute button. |
title | string | - | The title of the video, displayed at the top when in full-screen mode. |
play-btn-position | string | bottom | The position of the play button. Valid value is 'bottom' (on the controls bar). Valid value is 'center' (in the middle of the video). |
enable-play-gesture | boolean | false | Whether to enable play gestures, i.e., double-tap to toggle between play/pause. |
auto-pause-if-navigate | boolean | true | Whether to automatically pause the video on this page when redirecting to other mini program pages. |
auto-pause-if-open-native | boolean | true | Whether to automatically pause the video on this page when redirecting to other native pages. |
bindplay | eventhandle | - | The 'play' event is triggered when playback starts or resumes. |
bindpause | eventhandle | - | The 'pause' event is triggered when playback pauses. |
bindended | eventhandle | - | The 'ended' event is triggered when playback reaches the end. |
bindtimeupdate | eventhandle | - | The event is triggered when the playback progress changes, with event.detail = {currentTime, duration}. The triggering frequency is once every 250 ms. |
bindfullscreenchange | eventhandle | - | The event is triggered when the video enters or exits full screen, with event.detail = {fullScreen, direction}. The valid values for direction are 'vertical' or 'horizontal'. |
bindwaiting | eventhandle | - | The event is triggered when the video experiences buffering. |
binderror | eventhandle | - | The event is triggered when an error occurs during video playback. |
bindprogress | eventhandle | - | The event is triggered when the loading progress changes, supporting only loading of a section. The event.detail = {buffered}, expressed as a percentage. |
<video>
are 300px in width and 225px in height, which can be adjusted via wxss.<view class="section tc"><video src="{{src}}" controls></video><view class="btn-area"><button bindtap="bindButtonTap">Get video</button></view></view><view class="section tc"><videoid="myVideo"src="https://qzonestyle.gtimg.cn/qzone/qzact/act/external/qq-video/qq-video.mp4"danmu-list="{{danmuList}}"enable-danmudanmu-btncontrols></video><view class="btn-area"><button bindtap="bindButtonTap">Get video</button><input bindblur="bindInputBlur" /><button bindtap="bindSendDanmu">Dispatch the barrage</button></view></view>
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 : colorrgb.push(color)}return '#' + rgb.join('')}Page({onReady(res) {this.videoContext = wx.createVideoContext('myVideo')},inputValue: '',data: {src: '',danmuList: [{text: 'Barrage appearing at the 1st second',color: '#ff0000',time: 1},{text: 'Barrage appearing at the 3rd second',color: '#ff00ff',time: 3}]},bindInputBlur(e) {this.inputValue = e.detail.value},bindButtonTap() {const that = thiswx.chooseVideo({sourceType: ['album', 'camera'],maxDuration: 60,camera: ['front', 'back'],success(res) {that.setData({src: res.tempFilePath})}})},bindSendDanmu() {this.videoContext.sendDanmu({text: this.inputValue,color: getRandomColor()})}})
Attribute | Type | Default value | Required | Description | Earliest Version |
resource-width | number | 800 | No | The width of the video resource used by the component (unit: px) | 1.4.99 |
resource-height | number | 400 | No | The height of the video resource used by the component (unit: px) | 1.4.99 |
canvas-style | string | width: 400px;height: 400px; | No | Used to set the CSS style of the animation canvas | 1.4.99 |
path | string | | Yes | The animation resource address, supporting both relative paths and remote addresses. If it is a remote address, the | 1.4.99 |
loop | boolean | false | No | Whether to enable loop playback of animation. | 1.4.99 |
autoplay | boolean | false | No | Whether the animation is automatic. | 1.4.99 |
alpha-direction | string | left | No | The direction of the alpha channel in the video resource; 'left' indicates that the alpha channel is on the left side of the resource, while 'right' signifies that the alpha channel is on the right side of the resource. | 1.4.99 |
bindstarted | eventhandle | - | No | Callback for the commencement of the animation playback | 1.4.99 |
bindended | eventhandle | - | No | The 'ended' event is triggered when playback reaches the end (a callback is triggered upon natural playback completion, but not when looped playback ends or the animation pauses). | 1.4.99 |
<view class="wrap"><view class="card-area"><view class="top-description border-bottom"><view>The animation's alpha channel information is on the right side of the video</view><view>alpha-direction='right'</view></view><view class="video-area"><animation-videopath="{{rightAlphaSrcPath}}"loop="{{loop}}"resource-width="800"resource-height="400"canvas-style="width:200px;height:200px"autoplay="{{autoplay}}"bindstarted="onStarted"bindended="onEnded"alpha-direction='right'></animation-video></view></view><view class="card-area"><view class="top-description border-bottom"><view>The animation's alpha channel information is on the left side of the video</view><view>alpha-direction='left'</view></view><view class="video-area"><animation-videopath="{{leftAlphaSrcPath}}"loop="{{loop}}"resource-width="800"resource-height="400"canvas-style="width:200px;height:200px"autoplay="{{autoplay}}"bindstarted="onStarted"bindended="onEnded"alpha-direction='left'></animation-video></view></view></view>Page({data: {loop: true,leftAlphaSrcPath: 'https://efe-h2.cdn.bcebos.com/ceug/resource/res/2020-1/1577964961344/003e2f0dcd81.mp4',rightAlphaSrcPath: 'https://b.bdstatic.com/miniapp/assets/docs/alpha-right-example.mp4',autoplay: true},onStarted() {console.log('===onStarted');},onEnded() {console.log('===onEnded');}})
Attribute | Type | Default value | Description |
mode | string | normal | Valid values are 'normal', 'scanCode'. |
device-position | string | back | Front or rear, with values being 'front', 'back'. |
flash | string | auto | Flashlight, with values being 'auto', 'on', 'off'. |
bindstop | eventhandle | - | The camera is triggered in the event of an abnormal termination, such as exiting the backend and other situations. |
binderror | eventhandle | - | Triggered when the user does not permit the use of the camera. |
bindscancode | eventhandle | - | Triggered upon successful scan code recognition, effective only when mode is set to 'scanCode'. |
<!-- camera.wxml --><cameradevice-position="back"flash="off"binderror="error"style="width: 100%; height: 300px;"></camera><button type="primary" bindtap="takePhoto">Take Photo</button><view>Preview</view><image mode="widthFix" src="{{src}}"></image>
// camera.jsPage({takePhoto() {const ctx = wx.createCameraContext()ctx.takePhoto({quality: 'high',success: (res) => {this.setData({src: res.tempImagePath})}})},error(e) {console.log(e.detail)}})
Attribute | Type | Default value | Required | Description | Earliest Version |
src | string | - | No | Audio and video address. Currently, only flv and rtmp formats are supported. | 1.4.96 |
mode | string | live | No | Mode | 1.4.96 |
autoplay | boolean | false | No | Auto play | 1.4.96 |
muted | boolean | false | No | Whether to mute | 1.4.96 |
orientation | string | vertical | No | Screen Orientation | 1.4.96 |
object-fit | string | contain | No | Filling mode, with optional values being "contain" and "fillCrop". | 1.4.96 |
min-cache | number | 1 | No | Minimum buffer zone, measured in seconds. | 1.4.96 |
max-cache | number | 3 | No | Maximum buffer zone, measured in seconds. | 1.4.96 |
sound-mode | string | speaker | No | Audio Output Method | 1.4.96 |
auto-pause-if-navigate | boolean | true | No | When redirecting to another mini program page, should the real-time audio and video playback on the current page be automatically paused? | 1.4.96 |
auto-pause-if-open-native | boolean | true | No | When redirecting to another QQ native page, should the real-time audio and video playback on the current page be automatically paused? | 1.4.96 |
enable-metadata | boolean | false | No | Should metadata be called back? | 1.4.96 |
bindstatechange | eventhandle | - | No | Playback status change event, detail = {code} | 1.4.96 |
bindfullscreenchange | eventhandle | - | No | Full screen change event, detail = {direction, fullScreen} | 1.4.96 |
bindnetstatus | eventhandle | - | No | Network status notification, detail = {info} | 1.4.96 |
bindmetadatachange | eventhandle | - | No | Metadata notification, detail = {info} | 1.4.96 |
Value | Description | Earliest Version |
live | Live stream | 1.4.96 |
Value | Description | Earliest Version |
vertical | Vertical | 1.4.96 |
horizontal | Horizontal | 1.4.96 |
Value | Description | Earliest Version |
contain | The longer dimension of the image fills the screen, while the shorter dimension is filled with black. | 1.4.96 |
fillCrop | The image spans the entire screen, with portions exceeding the display area being cropped. | 1.4.96 |
Value | Description | Earliest Version |
speaker | Speaker | 1.4.96 |
Code | Description |
2001 | Successfully connected to the server. |
2002 | Successfully connected to the server, initiating stream pull. |
2003 | The network has received the first video data packet (IDR). |
2004 | Video playback has commenced. |
2006 | Video playback has concluded. |
2007 | Video playback is loading. |
2008 | The decoder has been activated. |
2009 | The video resolution has been altered. |
-2301 | The network has been disconnected, and multiple reconnection attempts have proven futile. For further attempts, please manually restart the playback. |
-2302 | Acquisition of the accelerated streaming address has failed. |
2101 | The current video frame has failed to decode. |
2102 | The current audio frame has failed to decode. |
2103 | The network connection was disrupted. Automatic reconnection has been initiated. |
2104 | The network packet reception is unstable. This could be due to insufficient downstream bandwidth, or uneven streaming from the broadcaster's end. |
2105 | The current video playback is experiencing lag. |
2106 | Hardware decoding initiation has failed, and software decoding is being used. |
2107 | The current video frame is discontinuous, likely resulting in frame loss. |
2108 | The hardware decoding of the first I-frame in the current stream has failed. The SDK has automatically switched to software decoding. |
3001 | RTMP - DNS resolution has failed. |
3002 | Failed to connect to the RTMP server. |
3003 | Failed to establish a handshake with the RTMP server. |
3005 | RTMP read/write operation has failed. |
Key Name | Description |
videoBitrate | Current video data reception bitrate, measured in kilobits per second (kbps). |
audioBitrate | Current audio data reception bitrate, measured in kilobits per second (kbps). |
videoFPS | Current video frame rate |
videoGOP | Current video GOP, which refers to the duration between two keyframes (I-frames), measured in seconds (s). |
netSpeed | Current transmission/reception speed |
netJitter | Network jitter conditions. The greater the jitter, the more unstable the network. |
videoWidth | Video frame width |
videoHeight | Video frame height |
<live-player id="playerid" src="https://domain/pull_stream" mode="live" autoplay bindstatechange="statechange" binderror="error" />
Page({statechange(e) {console.log('live-player code:', e.detail.code)},error(e) {console.error('live-player error:', e.detail.errMsg)}})
live-player
are 300px and 225px respectively, which can be adjusted via wxss.scope.camera
and scope.record
.Attribute | Type | Default value | Required | Description | Earliest Version |
url | string | - | No | Streaming address. Currently, only rtmp is supported. | 1.4.96 |
mode | string | RTC | No | SD (Standard Definition), HD (High Definition), FHD (Full High Definition), RTC (Real-Time Communication) | 1.4.96 |
autopush | boolean | false | No | Automatic streaming | 1.4.96 |
muted | boolean | false | No | Whether to mute | 1.4.96 |
enable-camera | boolean | true | No | Turn on camera | 1.4.96 |
auto-focus | boolean | true | No | Automatic aggregation | 1.4.96 |
orientation | string | vertical | No | Screen Orientation | 1.4.96 |
beauty | number | 0 | No | Beauty filter, with a value range of 0-9, where 0 indicates it is turned off. | 1.4.96 |
whiteness | number | 0 | No | Whitening effect, with a value range of 0-9, where 0 indicates it is turned off. | 1.4.96 |
aspect | string | 9:16 | No | Aspect ratio, with optional values of 3:4 and 9:16. | 1.4.96 |
min-bitrate | number | 200 | No | Minimum bitrate | 1.4.96 |
max-bitrat | number | 1000 | No | Maximum bitrate | 1.4.96 |
audio-quality | string | height | No | High-quality audio (48KHz) or low-quality audio (16KHz), with values being 'high' or 'low'. | 1.4.96 |
waiting-image | string | - | No | The standby screen displayed when streaming is initiated in the backend. | 1.4.96 |
waiting-image-hash | string | - | No | MD5 value of the standby screen resource. | 1.4.96 |
zoom | boolean | false | No | Focal length adjustment | 1.4.96 |
device-position | string | - | No | Front or rear, with values being 'front' and 'back'. | 1.4.96 |
background-mute | boolean | false | No | Mute status when entering the backend. | 1.4.96 |
mirror | boolean | false | No | Setting whether the streaming screen is mirrored, with the effect reflected in the live-player. | 1.4.96 |
bindstatechange | eventhandle | - | No | Status change event, detail = {code} | 1.4.96 |
bindnetstatus | eventhandle | - | No | Network status notification, detail = {info} | 1.4.96 |
binderror | eventhandle | - | No | Rendering error event, detail = {errMsg, errCode}. | 1.4.96 |
bindbgmstart | eventhandle | - | No | Triggered when the background sound begins to play. | 1.4.96 |
bindbgmprogress | eventhandle | - | No | Triggered when the background sound progress changes, detail = {progress, duration}. | 1.4.96 |
bindbgmcomplete | eventhandle | - | No | Triggered when the play of background sound completes. | 1.4.96 |
audio-reverb-type | number | 0 | No | Reverb mode (0-6): "Reverb off", "KTV", "Small room", "Large hall", "Deep", "Resonant", "Magnetic", respectively. | 1.4.96 |
Value | Description | Earliest Version |
vertical | Vertical | 1.4.96 |
horizontal | Horizontal | 1.4.96 |
Code | Description |
10001 | User has prohibited the use of the camera. |
10002 | User has prohibited the use of audio recording. |
10003 | Background sound resource (BGM) failed to load. |
10004 | Failed to load the waiting page resource (waiting-image). |
Code | Description |
1001 | Successfully connected to the streaming server. |
1002 | Handshake with the server has been successfully completed, initiating streaming. |
1003 | Successfully activated the camera. |
1004 | Screen recording has been successfully initiated. |
1005 | Dynamically adjust streaming resolution. |
1006 | Dynamically adjust streaming bitrate. |
1007 | The first frame has been successfully captured. |
1008 | The encoder has been activated. |
-1301 | Failed to activate the camera. |
-1302 | Failed to activate the microphone. |
-1303 | Video encoding failed. |
-1304 | Audio encoding failed. |
-1305 | Unsupported video resolution. |
-1306 | Unsupported audio sampling rate. |
-1307 | Network disconnection has occurred, and multiple attempts to reconnect have proven ineffective. For further attempts, please manually restart the streaming. |
-1308 | Screen recording initiation has failed, possibly due to user rejection. |
-1309 | Screen recording has failed due to an unsupported Android system version. A system version of 5.0 or newer is required. |
-1310 | Screen recording has been interrupted by another application. |
-1311 | The Android Mic has been successfully activated. However, it is unable to record audio data. |
-1312 | The dynamic switch between landscape and portrait modes during screen recording has failed. |
1101 | Poor network conditions: Insufficient upstream bandwidth is causing obstruction to data upload. |
1102 | The network connection was disrupted. Automatic reconnection has been initiated. |
1103 | Hardware encoding initiation has failed, and software encoding is being used. |
1104 | Video encoding failed. |
1105 | The initiation of the new beauty software encoding has failed, and the previous software encoding is being used. |
1106 | The initiation of the new beauty software encoding has failed, and the previous software encoding is being used. |
3001 | RTMP - DNS resolution has failed. |
3002 | Failed to connect to the RTMP server. |
3003 | Failed to establish a handshake with the RTMP server. |
3004 | The RTMP server has actively disconnected. Please verify the legitimacy of the streaming address or the validity period of the anti-leech protection. |
3005 | RTMP read/write operation has failed. |
Key Name | Description |
videoBitrate | The current output bitrate of the video encoder/decoder, measured in kilobits per second (kbps). |
audioBitrate | The current output bitrate of the audio encoder/decoder, measured in kilobits per second (kbps). |
videoFPS | Current video frame rate |
videoGOP | Current video GOP, which refers to the duration between two keyframes (I-frames), measured in seconds (s). |
netSpeed | Current transmission/reception speed |
netJitter | Network jitter conditions. The greater the jitter, the more unstable the network. |
videoWidth | Video frame width |
videoHeight | Video frame height |
<live-pusher url="https://domain/push_stream" mode="RTC" autopush bindstatechange="statechange" style="width: 300px; height: 225px;" />Page({statechange(e) {console.log('live-pusher code:', e.detail.code)}})
Was this page helpful?