


Implement live broadcast function of mini program through live broadcast component
1. Introduction
WeChat provides a live broadcast component for mini program developers. By calling this component, merchants can implement the live broadcast function in mini programs.
(Learning video sharing: Programming video)
Let’s introduce how to introduce the live broadcast component into the mini program.
2. Instructions for use
1. [Live broadcast component] How to introduce
Version restrictions:
WeChat client version 7.0.7 and above ( Basic library version 2.9.x and above supports same-layer rendering) you can watch live broadcasts and use the live broadcast room functions. Lower versions will prompt users to upgrade the WeChat client version when they first enter the live broadcast room (lower versions can only watch live broadcasts and cannot use the live broadcast room. function).
Introduce the [Live Streaming Component] live-player-plugin code package into the subpackage, and reference the app.json in the project root directory. The sample code is as follows:
{ "subpackages": [ { "root": "packageA", "pages": [ "pages/home/home" ], "plugins": { "live-player-plugin": { "version": "1.0.0", // 填写该直播组件最新版本号,微信开发者工具调试时可获取最新版本号 "provider": "wx2b03c6e691cd7370" // 必须填该直播组件appid,该示例值即为直播组件appid } } } ] }
2. [Live Streaming Component] How to After using
to introduce the component code package configuration according to the method in step 1, you can directly jump to the live broadcast component page through the link address (that is, enter the live broadcast room page). The link address needs to bring the live broadcast room ID; The room ID can be obtained through the [Get Live Room List] API below. The sample code is as follows:
<navigator url="plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=[直播房间id]"> Go to Live Player page </navigator>
You can jump to the live broadcast component page through this link (the current page entrance is only open to 'live-player-plugin ').
The sample renderings are as follows:
3. Other related components, interfaces and carrying parameters
● Subscription Component: subscribe
● Get live broadcast status API: getLiveStatus
● Parameters carried from the live broadcast room to the business details page: room_id
● Parameters carried when returning from the group sharing card to the live broadcast room : Shareticket
● Get the live broadcast room list in the background API
● In the background to get back source video API
Note: The total upper limit of the interface of the above 2 background calls 500 times/day
1. 【Subscription】Component
Function explanation:
Users enter the live broadcast room and can make a single subscription to a live broadcast that has not yet started. When the broadcast starts, the live broadcast component will Automatically distribute broadcast start reminders to users, without the need for developers to develop additional
component usage:
If you need to have the same start broadcast reminder function on other pages of the mini program other than the live broadcast component page, you can introduce [ Subscription] component subscribe; you need to reference the subscription component in home.json of the page page (such as the home page). The sample code is as follows:
{ "usingComponents": { "subscribe": "plugin-private://wx2b03c6e691cd7370/components/subscribe/subscribe" } }
Then you can use the subscription component in home.wxml, where the live broadcast room id can be Passed; the room id can be obtained through the following [Get live broadcast room list] API
<subscribe room-id="[直播房间id]"></subscribe>
2. [Get live broadcast status] interface
Interface description:
Get it for the first time and return to the live broadcast immediately Status, polling will be performed at intervals of 1 minute or slower to obtain the live broadcast status;
Live broadcast status description:
l 101 Live Broadcast: Indicates that the anchor is starting to broadcast normally and the live broadcast is in a normal state;
l 102 Not Started: Indicates that the host has not started the broadcast;
l 103 Ended: Indicates that the live broadcast is closed normally by clicking the [End] button on the live broadcast end, or the system forces the live broadcast to be abnormal after 15 minutes Ended live broadcast;
l 104 Banned: Indicates that the broadcast is banned due to operational penalties due to violations;
l 105 Paused: Indicates that the live broadcast has been paused by operating in the MP applet background-console ;
l 106 Abnormal: Indicates that the anchor leaves, switches to the background, disconnects from the Internet, etc. The live broadcast is judged to be in an abnormal state, and it can return to the normal live broadcast state after resuming within 15 minutes; if the live broadcast continues after 15 minutes, If it is not restored, the live broadcast room will be forced to end the live broadcast by the system;
l 107 Expired: It means that the live broadcast room has not started broadcasting, and the live broadcast plan end time filled in when creating the live broadcast room in the MP applet background has been reached, then The live broadcast has been judged to have expired and cannot be broadcast again;
Calling method:
To call the [Get Live Broadcast Status] interface getLiveStatus, you need to quote [Live Streaming Component] live-player at the top of the mini program page -plugin, the sample code is as follows:
let livePlayer = requirePlugin('live-player-plugin') //Introducing the interface to obtain the live broadcast status
//The first time it is obtained, it will return to the live broadcast status immediately, and then Poll to obtain the live broadcast status at an interval of 1 minute or slower
const roomId = xxx // 房间id livePlayer.getLiveStatus({ room_id: roomId }) .then(res => { // 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常,107:已过期 const liveStatus = res.liveStatus }) .catch(err => { console.log(err) })
3. Carrying parameters
Version restrictions:
Live broadcast component version 1.0.1 and above supports carrying The following parameters
shareTicket: Share the live broadcast room card to the WeChat group. After clicking this card, you can obtain the parameters in ApponShow
room_id: Click When the shelf products in the live broadcast component page jump to the product details page of the merchant applet, they will bring the room number parameter
4. The [Get Live Broadcast Room List] interface is for backend only Call
Interface rules:
该接口仅供商家后台调用,调用限额500次/天,建议开发者自己做缓存(此接口与下面【获取回放视频】接口共用500次/天限制,请合理分配调用频次)。
请求URL:
http://api.weixin.qq.com/wxa/business/getliveinfo?access_token=
请求方式:
POST
请求示例:
Request { "start": 0, // 起始拉取房间,start=0表示从第1个房间开始拉取 "limit": 10 // 每次拉取的个数上限,不要设置过大,建议100以内 } Response { "errcode": 0, // errcode=0代表成功;errcode=1代表未创建直播房间 "errmsg": "ok", "room_info": [{ "name": "直播房间名", "roomid": 1, "cover_img": "http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/Rl1RuuhdstSfZa8EEljedAYcbtX3Ejpdl2et1tPAQ37bdicnxoVialDLCKKDcPBy8Iic0kCiaiaalXg3EbpNKoicrweQ\/0?wx_fmt=jpeg", "live_satus": 101, "start_time": 1568128900, "end_time": 1568131200, "anchor_name": "李四", "anchor_img": "http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/Rl1RuuhdstSfZa8EEljedAYcbtX3Ejpdlp0sf9YTorOzUbGF9Eib6ic54k9fX0xreAIt35HCeiakO04yCwymoKTjw\/0?wx_fmt=jpeg", "goods":[ { "cover_img":"http://mmbiz.qpic.cn/mmbiz_png/FVribAGdErI2PmyST9ZM0JLbNM48I7TH2FlrwYOlnYqGaej8qKubG1EvK0QIkkwqvicrYTzVtjKmSZSeY5ianc3mw/0?wx_fmt=png", "url":"pages/index/index.html", "price":1100, "name":"fdgfgf" } ], "total":1 }
返回字段:
name 房间名
roomid 房间id
注:需先在小程序MP后台创建直播房间,否则会报错(错误码1)
cover_img 封面图片url
start_time 直播计划开始时间,列表按照 start_time 降序排列
end_time 直播计划结束时间
anchor_name 主播名
goods 商品列表
live_status 直播状态 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常,107:已过期(直播状态解释可参考【获取直播状态】接口)
5. 【获取回放源视频】接口,仅供后台调用
接口规则:
该接口仅供商家后台调用,调用限额500次/天,此接口与上面【获取房间列表】接口共用500次/天限制,请合理分配调用频次)。
接口说明:
该接口可在直播结束后拿到回放源视频(直播结束后大约10分钟会生成回放,源视频无评论等内容)
拿到源视频后需要开发者自行开发、使用回放视频
如果把源视频直接放在小程序上使用,需要小程序具备视频资质(具体资质要求请参考《小程序开发的类目服务》)
后续官方会直接提供无需开发的直播回放功能,敬请期待。
请求URL:
http://api.weixin.qq.com/wxa/business/getliveinfo?access_token=
请求方式:
POST
请求示例:
Request { "action": "get_replay", // 获取回放 "room_id": 354, // 直播间id "start": 0, // 起始拉取视频,start=0表示从第1个视频片段开始拉取 "limit": 10 // 每次拉取的个数上限,不要设置过大,建议100以内 } Response { "live_replay": [ { "expire_time": "2020-11-11T03:49:55Z", // 回放视频url过期时间 "create_time": "2019-11-12T03:49:55Z", // 回放视频创建时间 "media_url": "http://xxxxx.vod2.myqcloud.com/xxxxx/xxxxx/f0.mp4" // 回放视频 } ], "errcode": 0, "total": 1, "errmsg": "ok" } // 一场直播可能会产生多个视频片段。
四、其他说明
1、直播间小程序码
说明:
小程序引入直播组件后必须进行一次小程序发布上线,否则小程序码不生效
在MP小程序直播后台创建好直播间后,可以直接拿到直播间分享小程序码,无需额外开发
如果商家在后台自己生成的直播间小程序码,需要做以下配置(否则直播间左上角返回键将失效):
在跳转进入直播间的路径加上 type=9 标识场景入口为小程序码:
"plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=[直播房间id]&type=9"
2、商家公众号文章添加小程序卡片
说明:
商家在公众号文章中添加跳转进入直播间的小程序卡片时,需要做以下配置(否则直播间左上角返回键将失效):
在跳转进入直播间的路径加上 type=10 标识场景入口为小程序卡片:
"plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=[直播房间id]&type=10"
3、商品详情页面需添加返回按钮
点击直播组件页面里的货架商品跳转到商家小程序的商品详情页面后,为了避免用户无法再返回直播间,商家需在小程序商品详情页面左上角加上返回按钮,用于返回到直播组件页面。
4、快速更新直播组件版本的方法
商家小程序对应的管理员微信号收到【公众平台安全助手】下发的直播组件版本更新的服务通知后,可点击通知进行快速发布,移动端即可快速更新小程序内直播组件的新版本,无需修改代码或重新提交审核。
服务通知如下图所示:
相关推荐:小程序开发教程
The above is the detailed content of Implement live broadcast function of mini program through live broadcast component. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the popularity of mobile Internet technology and smartphones, WeChat has become an indispensable application in people's lives. WeChat mini programs allow people to directly use mini programs to solve some simple needs without downloading and installing applications. This article will introduce how to use Python to develop WeChat applet. 1. Preparation Before using Python to develop WeChat applet, you need to install the relevant Python library. It is recommended to use the two libraries wxpy and itchat here. wxpy is a WeChat machine

Mini programs can use react. How to use it: 1. Implement a renderer based on "react-reconciler" and generate a DSL; 2. Create a mini program component to parse and render DSL; 3. Install npm and execute the developer Build npm in the tool; 4. Introduce the package into your own page, and then use the API to complete the development.

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l

How uniapp can achieve rapid conversion between mini programs and H5 requires specific code examples. In recent years, with the development of the mobile Internet and the popularity of smartphones, mini programs and H5 have become indispensable application forms. As a cross-platform development framework, uniapp can quickly realize the conversion between small programs and H5 based on a set of codes, greatly improving development efficiency. This article will introduce how uniapp can achieve rapid conversion between mini programs and H5, and give specific code examples. 1. Introduction to uniapp unia

Mini program registration operation steps: 1. Prepare copies of personal ID cards, corporate business licenses, legal person ID cards and other filing materials; 2. Log in to the mini program management background; 3. Enter the mini program settings page; 4. Select " "Basic Settings"; 5. Fill in the filing information; 6. Upload the filing materials; 7. Submit the filing application; 8. Wait for the review results. If the filing is not passed, make modifications based on the reasons and resubmit the filing application; 9. The follow-up operations for the filing are Can.

According to news from this site on October 31, on May 27 this year, Ant Group announced the launch of the "Chinese Character Picking Project", and recently ushered in new progress: Alipay launched the "Chinese Character Picking-Uncommon Characters" mini program to collect collections from the society Rare characters supplement the rare character library and provide different input experiences for rare characters to help improve the rare character input method in Alipay. Currently, users can enter the "Uncommon Characters" applet by searching for keywords such as "Chinese character pick-up" and "rare characters". In the mini program, users can submit pictures of rare characters that have not been recognized and entered by the system. After confirmation, Alipay engineers will make additional entries into the font library. This website noticed that users can also experience the latest word-splitting input method in the mini program. This input method is designed for rare words with unclear pronunciation. User dismantling

WeChat applet is a lightweight application that can be run on the WeChat platform. It does not require downloading and installation, which is convenient and fast. Java language, as a language widely used in enterprise-level application development, can also be used for the development of WeChat applets. In Java language, you can use the SpringBoot framework and third-party toolkits to develop WeChat applets. The following is a simple WeChat applet development process. To create a WeChat mini program, first, you need to register a mini program on the WeChat public platform. After successful registration, you can obtain

Implementation idea: Establishing the server side of thread, so as to process the various functions of the chat room. The establishment of the x02 client is much simpler than the server. The function of the client is only to send and receive messages, and to enter specific characters according to specific rules. To achieve the use of different functions, therefore, on the client side, you only need to use two threads, one is dedicated to receiving messages, and the other is dedicated to sending messages. As for why not use one, that is because, only
