Skip to content

Media Component

audio

  • Function Description Audio. This component has stopped maintenance, it is recommended to use wx.createInnerAudioContext instead.

  • Parameters and descriptions:

PropertiesTypeDefault valueRequiredDescription
idstring-NoUnique identifier of the audio component
srcstring-NoThe resource address of the audio to be played
loopbooleanfalseNoWhether to play in a loop
controlsbooleanfalseNoWhether to display the default control
posterstring-NoThe image resource address of the audio cover on the default control, if the controls attribute value is false, setting poster is invalid
namestringUnknown songNoThe audio name on the default control, if the controls attribute value is false, setting name is invalid
authorstringUnknown songNoThe author name on the default control, if the controls attribute value is false, setting author is invalid
binderroreventhandle-NoWhen an error occurs, the error event is triggered, detail = {errMsg:MediaError.code}
bindplayeventhandle-NoWhen starting/resuming playback, the play event is triggered
bindpauseeventhandle-NoWhen pausing playback, the pause event is triggered
bindtimeupdateeventhandle-NoWhen the playback progress changes, the timeupdate event is triggered, detail = {currentTime, duration}
bindendedeventhandle-NoThe ended event is triggered when the video reaches the end
  • Sample code:

wxml:

js
<!-- audio.wxml -->
<audio poster="{{poster}}" name="{{name}}" author="{{author}}" src="{{src}}" id="myAudio" controls loop></audio>

<button type="primary" bindtap="audioPlay">Playback</button>
<button type="primary" bindtap="audioPause">Pause</button>
<button type="primary" bindtap="audio14">Sets the current playback time to 14 seconds</button>
<button type="primary" bindtap="audioStart">Back to the beginning</button>

javascript:

js
// audio.js
Page({
  onReady: function (e) {
    // Uses wx.createAudioContext to get the audio context
    this.audioCtx = wx.createAudioContext("myAudio");
  },
  data: {
    poster:
      "http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000",
    name: "At The Moment",
    author: "Xu Wei",
    src: "http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&amp;uin=346897220&amp;vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&amp;fromtag=46",
  },
  audioPlay: function () {
    this.audioCtx.play();
  },
  audioPause: function () {
    this.audioCtx.pause();
  },
  audio14: function () {
    this.audioCtx.seek(14);
  },
  audioStart: function () {
    this.audioCtx.seek(0);
  },
});

image

  • Functional description: Image

  • Parameters and descriptions:

PropertiesTypeDefault valueDescription
srcstring-Image resource address
modestring'scaleToFill'Image cropping and scaling mode
show-menu-by-longpressbooleanfalseLong press the image to display a menu similar to saving the image
lazy-loadbooleanfalseImage lazy loading. Only valid for images under page and scroll-view
binderrorhandleevent-When an error occurs, the event name published to AppService, event object event.detail = {errMsg: 'something wrong'}
bindloadhandleevent-When the image is loaded, the event name published to AppService, event object event.detail = {height:'image height px', width:'image width px'}

TIP

  • The image component has a default width of 300px and a height of 225px
  • When the image component is scaled, the calculated width and height may contain decimals, and the decimal part may be erased when rendered under different webview kernels

Valid values

ModeValueDescription
ScalingscaleToFillScale the image without maintaining the aspect ratio, so that the width and height of the image are fully stretched to fill the image element
ScalingaspectFitScale the image while maintaining the aspect ratio, so that the long side of the image can be fully displayed. That is, the image can be displayed completely
ScalingaspectFillScale the image while maintaining the aspect ratio, and only ensure that the short side of the image can be fully displayed. That is, the image is usually only complete in the horizontal or vertical direction, and the other direction will be cut off
ScalingwidthFixThe width remains unchanged, the height changes automatically, and the aspect ratio of the original image remains unchanged
CroptopDo not scale the image, only display the top area of
CropbottomDo not scale the image, only display the bottom area of
CropcenterDo not scale the image, only display the middle area of
CropleftDo not scale the image, only display the left area of
CroprightDo not scale the image, only display the right area of
Croptop leftDo not scale the image, only display the upper left corner area of
Croptop rightDo not scale the image, only display the upper right corner area of
Cropbottom leftDo not scale the image, only display the lower left area of
Cropbottom rightDo not scale the image, only display the lower right area of

Sample code:

wxml:

js
<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">
        <image style="width: 200px; height: 200px; background-color: #eeeeee;" mode="{{item.mode}}" src="{{src}}"></image>
      </view>
    </view>
  </view>
</view>

javascript:

js
Page({
  data: {
    array: [
      {
        mode: "scaleToFill",
        text: "scaleToFill: Scales the image without preserving the aspect ratio, stretching it to fill the image element completely. ",
      },
      {
        mode: "aspectFit",
        text: "aspectFit: Scales the image while preserving the aspect ratio, ensuring the entire image is visible (long side fits).",
      },
      {
        mode: "aspectFill",
        text: "aspectFill: Scales the image while preserving the aspect ratio, ensuring the short side fits, potentially cropping the long side.",
      },
      {
        mode: "top",
        text: "top: Does not scale the image, only shows the top part.",
      },
      {
        mode: "bottom",
        text: "bottom: Does not scale the image, only shows the bottom part.",
      },
      {
        mode: "center",
        text: "center: Does not scale the image, only shows the center part.",
      },
      {
        mode: "left",
        text: "left: Does not scale the image, only shows the left part.",
      },
      {
        mode: "right",
        text: "right: Does not scale the image, only shows the right part.",
      },
      {
        mode: "top left",
        text: "top left: Does not scale the image, only shows the top-left part.",
      },
      {
        mode: "top right",
        text: "top right: Does not scale the image, only shows the top-right part.",
      },
      {
        mode: "bottom left",
        text: "bottom left: Does not scale the image, only shows the bottom-left part.",
      },
      {
        mode: "bottom right",
        text: "bottom right: Does not scale the image, only shows the top-right part.",
      },
    ],
    src: "https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg",
  },
  imageError: function (e) {
    console.log(
      "An error event is triggered in image3, and the carried value is",
      e.detail.errMsg
    );
  },
});

video

  • Functional description: video. The lower version is a native component, please pay attention when using it Native Component Usage restrictions.
PropertiesTypeDefault valueDescription
srcstring-The resource address of the video to be played, supports cloud file ID
durationnumber-Specify the video duration
controlsbooleantrueWhether to display the default playback controls (play/pause button, playback progress, time)
danmu-listObject Array-Bullet screen list
danmu-btnbooleanfalseWhether to display the bullet screen button, only valid at initialization, cannot be changed dynamically
enable-danmubooleanfalseWhether to display the bullet screen, only valid at initialization, cannot be changed dynamically
autoplaybooleanfalseWhether to play automatically
loopbooleanfalseWhether to play in a loop
mutedbooleanfalseWhether to play silently
initial-timenumber-Specify the initial playback position of the video
page-gesturebooleanfalseWhether to enable brightness and volume adjustment gestures in non-full screen mode
directionnumber-Set the direction of the video in full screen, if not specified, it will be automatically determined according to the aspect ratio
The valid value is 0 (normal vertical)
The valid value is 90 (90 degrees counterclockwise of the screen)
The valid value is -90 (90 degrees clockwise of the screen)
show-progressbooleantrueIf not set, it will be displayed only when the width is greater than 243
show-fullscreen-btnbooleantrueWhether to display the full screen button
show-play-btnbooleantrueWhether to display the play button in the control bar at the bottom of the video
show-center-play-btnbooleantrueWhether to display the play button in the middle of the video
enable-progress-gesturebooleantrueWhether to enable the progress control gesture
object-fitstringcontainWhen the video size is inconsistent with the video container size, the video presentation
Includes
Padding
Overlay
posterstring-The network resource address or cloud file ID of the video cover. If the controls attribute value is false, setting poster is invalid
show-mute-btnbooleanfalseWhether to display the mute button
titlestring-The title of the video, displayed at the top when in full screen
play-btn-positionstringbottomThe location of the play button:
Valid value is bottom (on the controls bar)
Valid value is center (in the middle of the video)
enable-play-gesturebooleanfalseWhether to enable the play gesture, that is, double-click to switch play/pause
auto-pause-if-navigatebooleantrueWhen jumping to other mini-program pages, whether to automatically pause the video on this page
auto-pause-if-open-nativebooleantrueWhen jumping to other native pages, whether to automatically pause the video on this page
vslide-gesturebooleanfalseIn non-full-screen mode, whether to enable the brightness and volume adjustment gesture (same as page-gesture)
vslide-gesture-in-fullscreenbooleantrueIn full-screen mode, whether to enable the brightness and volume adjustment gesture
picture-in-picture-modestring/Array-Set the small window mode: push, pop, empty string or set multiple modes in array form (such as: ['push', 'pop'])
enable-auto-rotationbooleanfalseWhether to enable automatic full screen when the phone is in landscape mode, effective when the system setting turns on automatic rotation
bindplayeventhandle-Trigger the play event when starting/resuming playback
bindpauseeventhandle-Trigger the pause event when pausing playback
bindendedeventhandle-Trigger the ended event when the playback reaches the end
bindtimeupdateeventhandle-Triggered when the playback progress changes, event.detail = {currentTime, duration}. Trigger frequency is once every 250ms
bindfullscreenchangeeventhandle-Triggered when the video enters and exits full screen, event.detail = {fullScreen, direction}, direction valid values ​​are vertical or horizontal
bindwaitingeventhandle-Triggered when video buffering occurs
binderroreventhandle-Triggered when video playback errors occur
bindprogresseventhandle-Triggered when the loading progress changes, only one section of loading is supported. event.detail = {buffered}, percentage
bindloadedmetadataeventhandle-Triggered when the video metadata loading is complete. event.detail = {width, height, duration}

TIP

<video> default width is 300px and height is 225px, width and height can be set through wxss.

  • Small window feature description:
The video small window supports the following three trigger modes (set the picture-in-picture-mode attribute on the component):
  • Push mode, that is, the small window appears when jumping from the current page to the next page (page stack push).

  • Pop mode, that is, triggered when leaving the current page (page stack pop).

  • Both of the above two routing behaviors trigger the small window.

In addition, the small window also supports the following features:
  • The small window container size will be automatically determined according to the original component size.

  • Clicking the small window will navigate the user back to the player page corresponding to the small window.

  • After the small window appears, the user can click the close button in the upper right corner of the small window or call the context.exitPictureInPicture() interface to close the small window.

When the player enters the small window mode, the page where the player is located is in the hide state (triggering the onHide life cycle), and the page will not be destroyed. When the small window is closed, the page where the player is located will be unloaded (triggering the onUnload life cycle).

Sample code:

wxml:

js
<view class="page-body">
 <view class="page-section tc">
   &lt;video
     id="myVideo"
     src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&amp;bizid=1023&amp;hy=SH&amp;fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400"
     binderror="videoErrorCallback"
     danmu-list="{{danmuList}}"
     enable-danmu
     danmu-btn
     show-center-play-btn='{{false}}'
     show-play-btn="{{true}}"
     controls
     picture-in-picture-mode="{{['push', 'pop']}}"
     bindenterpictureinpicture='bindVideoEnterPictureInPicture'
     bindleavepictureinpicture='bindVideoLeavePictureInPicture'
   ></video>
   <view style="margin: 30rpx auto" class="weui-label">On-screen comment content</view>
   <input bindblur="bindInputBlur" class="weui-input" type="text" placeholder="Type your on-screen comment here" />
   <button style="margin: 30rpx auto"  bindtap="bindSendDanmu" class="page-body-button" type="primary" formType="submit">Send on-screen comment</button>
   <navigator style="margin: 30rpx auto"  url="picture-in-picture" hover-class="other-navigator-hover">
     <button type="primary" class="page-body-button" bindtap="bindPlayVideo">Picture-in-picture mode</button>
   </navigator>
 </view>
</view>

javascript:

js
function getRandomColor() {
  const rgb = []
  for (let i = 0; i &lt; 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({
  onShareAppMessage() {
    return {
      title: 'video',
      path: 'page/component/pages/video/video'
    }
  },

  onReady() {
    this.videoContext = wx.createVideoContext('myVideo')
  },

  onHide() {

  },

  inputValue: '',
  data: {
    src: '',
    danmuList:
    [{
      text: 'The on-screen comment that appears in the first second',
      color: '#ff0000',
      time: 1
    }, {
      text: 'The on-screen comment that appears in the third second',
      color: '#ff00ff',
      time: 3
    }],
  },

  bindInputBlur(e) {
    this.inputValue = e.detail.value
  },

  bindButtonTap() {
    const that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: ['front', 'back'],
      success(res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },

  bindVideoEnterPictureInPicture() {
    console.log('Enters picture-in-picture mode')
  },

  bindVideoLeavePictureInPicture() {
    console.log ('Exits picture-in-picture mode')
  },

  bindPlayVideo() {
    console.log('1')
    this.videoContext.play()
  },
  bindSendDanmu() {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  },

  videoErrorCallback(e) {
    console.log ('Video error message: ')
    console.log(e.detail.errMsg)
  }
})

animation-video

  • Functional description: animation-video is a front-end component that provides the ability for mini programs to render specific video resources as transparent background animations, which can help developers achieve more immersive and rich animation effects at a low cost. The animation-video component also provides a rich API to control the playback, pause, jump to a specified position, etc. of the animation. For related APIs, see wx.createAnimationVideo

  • Parameters and descriptions:

PropertiesTypeDefault valueRequiredDescription
resource-widthnumber800NoThe width of the video resource used by the component (unit: px)
resource-heightnumber400NoThe height of the video resource used by the component (unit: px)
canvas-stylestringwidth:400px;
height:400px
NoThe CSS style used to set the animation canvas
pathstringNoAnimation resource address, supports relative paths and remote addresses. If it is a remote path, Access-Control-Allow-Origin needs to be set in the response header to prevent cross-domain issues
loopbooleanfalseNoWhether the animation is played in a loop
autoplaybooleanfalseNoWhether the animation is automatically
alpha-directionstringleftNoThe direction of the alpha channel in the video resource, left means the alpha channel is on the left side of the resource, right Indicates that the alpha channel is on the right side of the resource
bindstartedeventhandle-NoCallback for animation start
bindendedeventhandle-NoThe ended event is triggered when the playback reaches the end (the callback is triggered when the natural playback ends, but not when the loop playback ends or the animation is paused)

Sample code:

wxml:

js
<view class="wrap">
    <view class="card-area">
        <view class="top-description border-bottom">
            <view>Animation alpha channel information is on the right side of the video</view>
            <view>alpha-direction='right'</view>
        </view>
        <view class="video-area">
            &lt;animation-video
                path="{{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>Animation alpha channel information is on the left side of the video</view>
            <view>alpha-direction='left'</view>
        </view>
        <view class="video-area">
            &lt;animation-video
                path="{{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>

javascript:

js
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");
  },
});

camera

  • Function Description System camera, this component is Native Component , please pay attention to the relevant restrictions when using it, and the relevant API can be found in wx.createCameraContext

  • Parameters and descriptions:

PropertiesTypeLegal valuesDefault valueDescription
modestringnormal:Camera mode
scanCode:Scan code mode
normalApplication mode, only valid during initialization, cannot be changed dynamically
device-positionstringfront:Front
back:Rear
backCamera orientation
flashstringauto:Automatic
on:On
off:Off
torch:Always on
autoFlash, value is auto, on, off
bindstopeventhandle--The camera is triggered when it is abnormally terminated, such as exiting the background, etc.
binderroreventhandle--Triggered when the user does not allow the camera to be used
bindscancodeeventhandle--Triggered when the scan code recognition is successful, only effective when mode='scanCode'

TIP

  • Requires 'user authorization' scope.camera, scope.record.
  • Only one camera component can be inserted on the same page.
  • The onCameraFrame interface returns raw frame data of different sizes according to frame-size. Unlike the image displayed by the Camera component, its actual pixel value is determined by the system.

Sample code:

wxml:

js
<camera
device-position="back"
flash="off"
binderror="error"
style="width: 100%; height: 300px;"
></camera>
<button type="primary" bindtap="takePhoto">Photograph</button>
<view>Preview</view>
<image mode="widthFix" src="{{src}}"></image>
javascript:

```js
Page({
  takePhoto() {
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        this.setData({
          src: res.tempImagePath
        })
      }
    })
  },
  error(e) {
    console.log(e.detail)
  }
})

live-player

Functional description: Real-time audio and video playback. This component is a native component, please pay attention when using it Native components

Parameters and descriptions:

PropertiesTypeLegal valuesDefault valueDescription
srcstring--Audio and video address. Currently only flv and rtmp formats are supported
modestringlive: Live broadcast
RTC: Real-time call
liveMode
autoplayboolean-falseMode
mutedboolean-falseWhether to mute
orientationstringvertica: Vertical
horizontal: Horizontal
verticalDirection of screen
object-fitstringcontai: The long side of the image fills the screen, and the short side area will be filled with black
fillCrop: The image fills the screen, and the part beyond the display area will be cut off
containFill mode, optional values
min-cachenumber-1Minimum buffer, unit s (RTC mode recommended 0.2s)
max-cachenumber-3Maximum buffer, unit s (RTC mode recommended 0.8s), the buffer is used to resist network fluctuations, the more buffered data, the better the network resistance, but the greater the delay
sound-modestringspeaker: Speaker
ear: Earpiece
speakerApplication mode, only valid during initialization, cannot be changed dynamically
auto-pause-if-navigateboolean-trueWhen jumping to other mini program pages, whether to automatically pause the real-time audio and video playback of this page
auto-pause-if-open-nativeboolean-trueWhen jumping to other host APP native pages, whether to automatically pause the real-time audio and video playback of this page
picture-in-picture-modestring/Array[]: Cancel small window
push: Trigger small window when route pushes
push: Trigger small window when route pushes
-Set small window mode: push, pop, empty string or set multiple modes in array form (such as: ['push', 'pop'])
enable-auto-rotationboolean-falseWhether to turn on automatic full screen when the phone is in landscape mode, effective when the system setting turns on automatic rotation
enable-metadataboolean-falseWhether to callback metadata
bindstatechangeeventhandle--Playback status change event, detail = {code}
bindfullscreenchangeeventhandle--Full screen change event, detail = {direction, fullScreen}
bindnetstatuseventhandle--Network status notification, detail = {info}
bindaudiovolumenotifyeventhandle--Playback volume notification, detail = {}
bindenterpictureinpictureeventhandle--Player enters small window
bindleavepictureinpictureeventhandle--Player exits small window
bindmetadatachangeeventhandle--metadata notification, detail = {info}

status code

codeDescription
2001Connected to the server
2002Connected to the server, started streaming
2003The network received the first video data packet (IDR)
2004Video started playing
2006Video playback ended
2007Video playback Loading
2008Decoder started
2009Video resolution changed
-2301Network disconnected, and multiple reconnections were invalid. Please restart the playback for more retries
-2302Failed to obtain the accelerated streaming address
2101Current video frame decoding failed
2102Current audio frame decoding failed
2103Network disconnected, automatic reconnection started
2104Network packets are unstable. It may be due to insufficient downlink bandwidth or uneven outflow from the anchor end
2105Current video playback is stuck
2106Hard decoding failed to start, using soft decoding
2107Current video frames are discontinuous and may be lost
2108Current stream hard decoding of the first I frame failed, SDK automatically switched to soft decoding
3001RTMP -DNS resolution failed
3002RTMP server connection failed
3003RTMP server handshake failed
3005RTMP read/write failed

Network status data

Key nameDescription
videoBitrateCurrent video data receiving bit rate, unit: kbps
audioBitrateCurrent audio data receiving bit rate, unit: kbps
videoFPSCurrent video frame rate
videoGOPCurrent video GOP, that is, the interval between two key frames (I frames), unit: s
netSpeedCurrent sending/receiving speed
netJitterNetwork jitter, the greater the jitter, the more unstable the network
videoWidthVideo screen width
videoHeightVideo screen height

TIP

  • Live-player default width is 300px and height is 225px, and the width and height can be set through wxss.
  • Not supported on developer tools yet.

Small window feature description:

Video small window supports the following three trigger modes (set the picture-in-picture-mode attribute on the component):

  • Push mode, that is, the small window appears when jumping from the current page to the next page (page stack push).
  • Pop mode, that is, triggered when leaving the current page (page stack pop).
  • Both of the above two routing behaviors trigger the small window.
In addition, the small window also supports the following features:
  • The small window container size will be automatically determined according to the original component size.
  • Click the small window, and the user will be navigated back to the player page corresponding to the small window.
  • After the small window appears, the user can click the close button in the upper right corner of the small window or call the context.exitPictureInPicture() interface to close the small window.
When the player enters the small window mode, the page where the player is located is in the hide state (triggering the onHide life cycle), and the page will not be destroyed. When the small window is closed, the page where the player is located will be unloaded (triggering the onUnload life cycle.

Sample code:

wxml:

js
<live-player
  src="https://domain/pull_stream"
  mode="RTC"
  autoplay
  bindstatechange="statechange"
  binderror="error"
  style="width: 300px; height: 225px;"
/>

javescript:

js
Page({
  statechange(e) {
    console.log("live-player code:", e.detail.code);
  },
  error(e) {
    console.error("live-player error:", e.detail.errMsg);
  },
});

live-pusher

  • Functional description: Real-time audio and video recording (same-layer rendering is not supported yet).

  • Parameters and descriptions:

Properties
Type
Legal values
Default value
Description
url
string
-
-
Streaming address. Currently only supports rtmp
mode
string
-
RTC
SD (standard definition), HD (high definition), FHD (ultra-high definition), RTC (real-time call)
autopush
boolean
-
false
Automatic streaming
muted
boolean
-
false
Whether to mute
muted
boolean
-
false
Whether to mute
enable-camera
boolean
-
true
Open camera
auto-focus
boolean
-
true
Automatic focus
orientation
string
vertical:Vertical
horizontal:Horizontal
vertical
Screen direction
beauty
number
-
0
Beauty, value range 0-9, 0 means off
whiteness
number
-
0
Whitening, value range 0-9, 0 means off
aspect
string
-
9:16
Aspect ratio, optional values
min-bitrate
number
-
200
Minimum bit rate
max-bitrate
number
-
1000
Maximum bit rate
audio-quality
string
-
height
High quality (48KHz) or low quality (16KHz), value is high, low
waiting-image
string
-
-
Waiting screen for streaming when entering the background
waiting-image-hash
string
-
-
MD5 value of waiting screen resource
zoom
boolean
-
false
Adjust focal length
device-position
string
-
-
Front or rear, value is front, back
background-mute
boolean
-
false
Whether to mute when entering the background
mirror
boolean
-
false
Set whether the streaming screen is mirrored, the effect is reflected in the live-player
local-mirror
string
auto:Front camera mirrored, rear camera not mirrored
enable: Both front and rear cameras mirrored
disable: Both front and rear cameras not mirrored
auto
Control whether the local preview screen is mirrored
audio-reverb-type
number
0: Front camera mirrored, rear camera not mirrored
1: ktv
2: Both front and rear cameras mirrored
3: Both front and rear cameras not mirrored
4: Great hall
5: Deep
6: Loud
7: Metallic
0
Audio reverberation type
enable-mic
boolean
-
-
Turn the microphone on or off
enable-agc
boolean
-
false
Whether to turn on audio auto gain
enable-ans
boolean
-
false
Whether to turn on audio noise suppression
audio-volume-type
string
auto: Automatic
media: Media volume
voicecall: Call volume
auto
Volume type
video-width
number
-
360
Resolution width of the video stream pushed up
video-height
number
-
640
Resolution height of the video stream pushed up
bindstatechange
eventhandle
-
-
Status change event, detail = {code}
bindnetstatus
eventhandle
-
-
Network status notification, detail = {info}
binderror
eventhandle
-
-
Rendering error event, detail = {errMsg, errCode}
bindbgmstart
eventhandle
-
-
Trigger when background sound starts playing
bindbgmprogress
eventhandle
-
-
Triggered when the background sound progress changes, detail = {progress, duration}
bindbgmcomplete
eventhandle
-
-
Trigger when background sound finishes playing

TIP

  • Requires 'user authorization' scope.camera, scope.record.
  • Not currently supported on developer tools.
  • The default width of live-pusher is 100% and there is no default height. Please set the width and height through wxss.
  • Error code (errCode)
codeDescription
10001User is prohibited from using the camera
10002User is prohibited from using recording
10003Background sound resource (BGM) failed to load
10004Waiting page resource (waiting-image) failed to load
  • status code(code)
codeDescription
1001Connected to streaming server
1002Handshake with server completed, streaming started
1003Opened camera successfully
1004Screen recording started successfully
1005Dynamically adjust resolution of streaming
1006Dynamically adjust bitrate of streaming
1007First frame of picture acquisition completed
1008Encoder started
-1301Failed to open camera
-1302Failed to open microphone
-1303Failed to video encoding
-1304Failed to audio encoding
-1305Unsupported video resolution
-1306Unsupported audio sampling rate
-1307Network disconnected, and multiple reconnection rescue failed, please restart streaming for more retries
-1308Failed to start screen recording, may be rejected by the user
-1309Screen recording failed, unsupported Android system version, requires system 5.0 or above
-1310Screen recording was interrupted by other applications
-1311Android Mic opened successfully, but no audio data was recorded
-1312Screen recording failed to switch horizontal and vertical screens dynamically
1101Poor network conditions: uplink bandwidth is too small, data upload is blocked
1102Network disconnected, automatic reconnection has been started
1103Hard coding startup failed, soft coding is used
1104Video encoding failed
3001RTMP -DNS resolution failed
3002RTMP server connection failed
3003RTMP server handshake failed
3004RTMP server actively disconnected, please check the legitimacy of the push address or the validity period of the anti-hotlink
3005RTMP read/write failed
  • Network status data (info)
Key nameDescription
videoBitrateThe bit rate output by the current video encoder/decoder, unit: kbps
audioBitrateThe bit rate output by the current audio encoder/decoder, unit: kbps
videoFPSCurrent video frame rate
videoGOPCurrent video GOP, that is, the interval between every two key frames (I frames), unit: s
netSpeedCurrent sending/receiving speed
netJitterNetwork jitter, the greater the jitter, the more unstable the network
videoWidthThe width of the video screen
videoHeightThe height of the video screen
  • Sample code:

wxl:

js
<live-pusher
  url="https://domain/push_stream"
  mode="RTC"
  autopush
  bindstatechange="statechange"
  style="width: 300px; height: 225px;"
/>

javascript:

js
Page({
  statechange(e) {
    console.log("live-pusher code:", e.detail.code);
  },
});