微信直播小程序端集成源代码

article/2025/10/30 2:05:39

需要下载可执行的源代码的,请点我:https://github.com/firefac/p-media-livePlayer

废话不多说,上代码。

liveplayer.json

{"navigationBarTitleText": "直播演示","usingComponents": {"van-tab": "../../lib/tab/index","van-tabs": "../../lib/tabs/index","van-card": "../../lib/card/index","van-button": "../../lib/button/index","subscribe": "plugin-private://wx2b03c6e691cd7370/components/subscribe/subscribe","van-icon": "../../lib/icon/index","van-popup": "../../lib/popup/index"}
}

livePlayer.wml

<wxs module="dateUtil" src="../../../utils/timeUtil.wxs"></wxs><view class="container"><van-tabs bind:change="switchCate" active="{{tabIndex}}"><van-tab title="直播"><view class="noContent" wx:if="{{rooms.length == 0}}"><van-icon name="bullhorn-o" size="120rpx" /><view>没有更多直播啦~~</view></view><view class="live-container"><view class="item" wx:for="{{rooms}}" wx:for-index="index" wx:for-item="item" wx:key="id"><navigator url="plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id={{item.roomid}}"><view class="img-container"><image class="img" src="{{item.anchorImg}}" mode="aspectFill"></image><view class="label">{{liveStatus[item.liveStatus]}}</view></view></navigator><view class="bottom"><view class="text"><navigator url="plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id={{item.roomid}}" class="header"><text class="name">{{item.name}}</text><text wx:if="{{item.anchorName != ''}}" class="desc">主播:{{item.anchorName}}</text><text class="desc">直播时间:{{dateUtil.dateFormat(item.startTime)}} - {{dateUtil.dateFormat(item.endTime)}}</text></navigator><view class="subscribe" wx:if="{{item.liveStatus == 102}}"><subscribe room-id="{{item.roomid}}"></subscribe></view></view></view></view></view></van-tab><van-tab title="已结束"><view class="finished-live-container"><view class="item" wx:for="{{finishedRooms}}" wx:for-index="index" wx:for-item="item" wx:key="id"><image class="img" src="{{item.anchorImg}}" mode="aspectFit" background-size="cover"></image><view class="right"><navigator url="plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id={{item.roomid}}"><view class="text"><text class="name">{{item.name}}</text><text wx:if="{{item.anchorName != ''}}" class="desc">主播:{{item.anchorName}}</text><text class="desc">直播时间:{{dateUtil.dateFormat(item.startTime)}} - {{dateUtil.dateFormat(item.endTime)}}</text></view></navigator><view class="opration" wx:if="{{item.liveRoomReplyList.length > 0}}"><van-button type="info" size="small" data-room="{{item}}" bind:click="showHistoryPopup">观看回放</van-button></view></view></view></view></van-tab></van-tabs><van-popup show="{{ historyShow }}" bind:close="onClose"><video src="{{liveHistoryRoom.mediaUrl}}"></video></van-popup><!-- 联系客服 --><view class="contact"><contact-button style="opacity:0;position:absolute;" type="default-dark" session-from="weapp" size="27"></contact-button></view>
</view>

livePlayer.js

var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');Page({data: {rooms:[],historyShow: false,tabIndex: 0,pageNum: 1,pageSize: 5,lastPage: false,finishedRooms:[],finishedPageNum: 1,finishedPageSize: 5,finishedLastPage: false,liveHistoryRoom: {},liveStatus: {101: "直播中",102: "未开始",103: "已结束",104: "禁播",105: "暂停中",106: "异常",107: "已过期"}},onLoad: function () {    this.getRoomsList();    this.getFinishedRoomsList();    },// 页面分享onShareAppMessage: function() {let that = this;return {title: "快来费尔工坊一起玩直播吧",path: 'pages/tools/livePlayer/livePlayer'}},onPullDownRefresh() {wx.showNavigationBarLoading() //在标题栏中显示加载this.resetData();this.getRoomsList();this.getFinishedRoomsList();    wx.hideNavigationBarLoading() //完成停止加载wx.stopPullDownRefresh() //停止下拉刷新},resetData: function() {this.setData({rooms:[],pageNum: 1,lastPage: false,finishedRooms:[],finishedPageNum: 1,finishedLastPage: false})},getRoomsList: function() {let that = this;util.request(api.LiveRoomList, {statusList: [101, 102, 105, 106],sort: "asc",pageNum: this.pageNum,pageSize: this.pageSize}, "POST").then(function(res) {if (res.errcode === '0') {that.setData({rooms: that.data.rooms.concat(res.data.list)})if(that.data.pageNum == 1){that.syncLiveStatus(that.data.rooms[0])}if(res.data.list.length < that.data.pageSize){that.data.lastPage = true}}});},syncLiveStatus: function(room) {if(room == null){return}let that = thislet livePlayer = requirePlugin('live-player-plugin') // 引入获取直播状态接口// 首次获取立马返回直播状态,往后间隔1分钟或更慢的频率去轮询获取直播状态livePlayer.getLiveStatus({ room_id: room.roomid }).then(res => {// 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常, 107:已过期 const liveStatus = res.liveStatusif(room.liveStatus != liveStatus){let rooms = that.data.roomsrooms[0].liveStatus = liveStatusthat.setData({rooms: rooms})util.request(api.LiveRoomStatusUpdate, {id: room.id,roomid: room.roomid,liveStatus: liveStatus}, "POST").then(function(res) {});}}).catch(err => {console.log(err)})},getFinishedRoomsList: function() {let that = this;util.request(api.LiveRoomList, {statusList: [103, 104, 107],pageNum: this.pageNum,pageSize: this.pageSize}, "POST").then(function(res) {if (res.errcode === '0') {that.setData({finishedRooms: that.data.finishedRooms.concat(res.data.list)})if(res.data.list.length < that.data.finishedRoomsPageSize){that.data.finishedRoomsLastPage = true}}});},showHistoryPopup: function(e){var room = e.currentTarget.dataset.roomthis.setData({historyShow: true,liveHistoryRoom: room.liveRoomReplyList[0]});},onClose() {this.setData({historyShow: false,liveHistoryRoom: {}});},onReachBottom() {if(this.data.tabIndex == 0){if(this.data.lastPage){wx.showToast({title: '没有更多直播了',icon: 'none',duration: 2000});return false;}else{this.data.pageNum = this.data.pageNum + 1this.getRoomsList();}}else if(this.data.tabIndex == 0){if(this.data.finishedLastPage){wx.showToast({title: '没有更多内容了',icon: 'none',duration: 2000});return false;}else{this.data.finishedPageNum = this.data.finishedageNum + 1this.getFinishedRoomsList();}}},switchCate: function(event) {this.setData({tabIndex: event.detail.name})},onReady: function() {// 页面渲染完成},onShow: function() {// 页面显示},onHide: function() {// 页面隐藏},onUnload: function() {// 页面关闭}
})

livePlayer.wxss

.container {background: #fff;
}view, text {font-family: PingFangSC-Light, helvetica, 'Heiti SC';font-size: 29rpx;
}.finished-live-container{justify-content: space-between;  flex-wrap:wrap;box-sizing: content-box;background: #fff;width: 100%;
}
.finished-live-container .item {border-bottom: 1px solid #d9d9d9;margin: 0 20rpx;height: 264rpx;
}.finished-live-container .img {margin-top: 12rpx;margin-right: 12rpx;float: left;width: 32%;height: 240rpx;
}.finished-live-container .right {float: left;height: 264rpx;width: 65%;flex-flow: row nowrap;
}.finished-live-container .text {display: flex;flex-wrap: nowrap;flex-direction: column;justify-content: center;overflow: hidden;height: 180rpx;
}.finished-live-container .name {display: block;color: #333;line-height: 40rpx;font-size: 32rpx;
}.finished-live-container .desc {display: block;color: #666;line-height: 32rpx;font-size: 25rpx;
}.finished-live-container .price {display: block;color: #ab956d;line-height: 50rpx;font-size: 33rpx;
}.live-container {width: 750rpx;height: 100%;overflow: hidden;padding: 20rpx;
}.live-container .item {width: 100%;background: #fff;margin-bottom: 25rpx;
}.live-container .img-container{height: 420rpx;position: relative;
}.live-container .img {width: 100%;height: 420rpx;background: #fff;border-radius: 20rpx 20rpx 0rpx 0rpx;position: absolute;
}.live-container .label {height: 100%;width: 100%;background-color: rgba(0,0,0,0.3);text-align: center;color: #fff;position: absolute;font-size: 40px;background-size: 55rpx auto;padding: 160rpx 0rpx;border-radius: 20rpx 20rpx 0rpx 0rpx;
}.live-container .bottom {width: 100%;display: flex;flex-flow: row nowrap;box-shadow: 0px 2px  4px 1px #DDD;border-radius: 0rpx 0rpx 20rpx 20rpx;
}.live-container .text {padding: 20rpx;width: 100%;
}.live-container .name {width: 100%;display: block;color: #333;line-height: 50rpx;font-size: 32rpx;overflow: hidden;
}.live-container .capsule-tag {float: right;padding-right: 0rpx;padding-top: 8rpx;
}.live-container .zan-capsule + .zan-capsule {margin-left: 10px;
}.live-container .desc {width: 100%;display: block;color: #666;line-height: 40rpx;font-size: 28rpx;overflow: hidden;
}.live-container .subscribe {padding-top: 30rpx;
}.noContent{display: block;line-height: 80rpx;text-align: center;margin-top: 100rpx;font-size: 30rpx;color: #666666;
}.contact {height: 100rpx;width: 100rpx;border-radius: 100%;position: fixed;bottom: 96rpx;right: 20rpx;font-size: 20rpx;box-sizing: border-box;background: url("https://firefac-1259431066.picsh.myqcloud.com/5ufjlp0rw68jen3pctjha6kk6jl6v4x9.png") no-repeat center 21rpx;background-size: 55rpx auto;
}

 


http://chatgpt.dhexx.cn/article/URIiZDUd.shtml

相关文章

实现微信小程序直播的2种方式|7大场景解决方案

ZEGO 微信小程序直播SDK 可以在微信小程序中提供实时音视频直播服务&#xff0c;从而实现电商直播/在线教育/在线问诊/视频客服等各种业务场景。但是由于微信小程序的官方限制&#xff0c;在某些场景下需要额外使用 ZEGO 提供的小程序直播插件才能实现实时音视频直播功能。 本…

基于微信小程序做直播的截图(微信小程序发起视频直播)

第1部分&#xff1a;大至描述 用微信小程序来发起直播&#xff08;推流&#xff09;&#xff1b;用户即可以通过微信直接观看&#xff0c;也可以通过PC端web浏览器观看或通过手机浏览器观看。 第2部分&#xff1a;提示说明 图1&#xff0c;是小程序界面方面的截图&#xff08…

快速开发微信小程序直播--微信直播--小程序直播开发

微信小程序开发需要基于微信提供的开发者工具与 SDK。如果开发者对小程序开发流程不熟悉&#xff0c;建议先系统学习&#xff1a;微信小程序开发官方文档。 由于微信官方文档比较详细&#xff0c;本文对小程序开发流程中的框架说明、API 调用、组件使用等&#xff0c;不再赘述…

小程序直播开发教程

直播是最近比较火的一个风口&#xff0c;许多网络达人也通过直播实现了自己的第一桶金&#xff0c; 小程序也针对此提供了直播能力&#xff0c;方便开发者快速接入&#xff0c;那么我们来看下如何实现一个小程序直播功能吧。 首先需要需要有一个小程序账号&#xff0c;如果没有…

微信小程序接入直播

文章目录 微信小程序接入直播一.小程序配置1.添加/更改服务类目2.开通实时播放/录制音视频流 二.云直播服务器1.云直播申请2.云直播配置2-1添加域名2-2获取推流地址2-3获取播放地址 三.组件介绍1.live-pusher2.live-player 四.代码实现1.页面结构2.离线检测 微信小程序接入直播…

微信小程序之直播功能使用详解

文章目录 前言一、准备创建直播间基本信息推流直播样式配置 二、开发使用引入插件1. 主包引入2. 分包引入进入直播 三、关于订阅四、自定义自播 前言 小程序直播功能&#xff0c;分为使用官方自带的直播组件( live-player-plugin ,无需二次开发&#xff0c;开箱即用)&#xff…

小程序直播功能开发

近期为一家企业开发小程序&#xff0c;用户提出了在小程序中增加直播功能。所幸小程序本身就提供了直播组件。具体开发文档可见官方说明。 小程序直播是微信官方提供的商家经营工具。通过调用该组件&#xff0c;商家可以在小程序中实现直播互动与商品销售闭环。其开发部分主要…

微信小程序怎么直播?

我们目前使用的小程序都是支持直播功能的&#xff0c;小程序直播功能是通过小程序直播组件实现的&#xff0c;这是微信为商家提供的实时视频直播工具&#xff0c;可以帮助商家快速通过小程序向用户提供优质的直播内容。同时&#xff0c;借助小程序丰富的营销功能&#xff0c;使…

创客匠人:怎么用微信小程序直播?

无论是哪个直播平台提供直播服务&#xff0c;首先都必须要安装相应的手机app&#xff0c;而就是这么一个小小的操作&#xff0c;也能够把大批的用户拒之门外。为了让直播服务更加轻便&#xff0c;不需要这么繁琐的过程也能获取直播内容&#xff0c;微信小程序也加入直播行列。说…

PDF阅读器:你不可不学的标记精读法

孔子晚年喜读《易经》&#xff0c;反复研读&#xff0c;以致把捆竹书的牛皮绳子都磨断了三次&#xff0c;留下了“韦编三绝”的佳话。阅读的实质是什么&#xff0c;是要掌握书中要义。在阅读过程中勾画重点、勾画佳句、标记疑问&#xff0c;就是了解作者写作目的并与作者产生思…

爆发:大数据时代预见未来的新思维 (湛庐文化•财富汇) - 电子书下载 -(百度网盘 高清版PDF格式)...

爆发&#xff1a;大数据时代预见未来的新思维 (湛庐文化•财富汇)-艾伯特-拉斯洛•巴拉巴西 (Albert-Lszl Barabsi) 在线阅读 百度网盘下载(9jvg) 书名:爆发&#xff1a;大数据时代预见未来的新思维 (湛庐文化•财富汇) 作者:艾伯特-拉斯洛•巴拉巴西 (Albe…

学术研究入门,如何下载论文?

来源: AINLPer 微信公众号&#xff08;每日更新…&#xff09; 编辑: ShuYini 校稿: ShuYini 时间: 2021-11-16 有很多刚刚接触研究领域的小伙伴不知道怎么找论文和下载论文&#xff0c;这里作者结合自己的经验总结了一下&#xff0c;希望对你有帮助。 查找论文的方式主要有以下…

【工作感悟】java编程规范pdf下载

前言 要相信,你现在所有的努力和付出都会在将来的某一天回报给你! 首先阿里巴巴作为国内互联网行业的领头羊,培养了一代又一代的IT技术人才,很多想进阿里这些互联网大厂的程序员看中的不仅仅是高薪+丰厚的福利待遇,同样也看中了学习氛围以及人脉圈子,这些资源在你以后对你…

读书笔记 | 国富论(卷一)

半月未更新&#xff0c;期间主要窝在广州窝了半月左右&#xff0c;除了帮老姐带娃太闹心&#xff08;此处必须歌颂一下母亲的伟大&#xff09;&#xff0c;一切还不错。除工作&#xff0c;带娃外&#xff0c;还陪母上大人桂林阳朔游&#xff0c;拜访中大的老师和博士&#xff0…

性能本质论

摘要 对于开发者、技术管理者、架构师、系统分析师和项目经理来说&#xff0c;创建具备高性能特征的复杂软件都是一件极其困难的事。然而&#xff0c;通过了解一些基本原理&#xff0c;性能问题的解决和预防可以更简单可靠。本文讲述了这些基本原理&#xff0c;涵盖了一系列的目…

Python轻松实现PDF格式转换(附详细源码)

公众号后台回复“图书“&#xff0c;了解更多号主新书内容 作者&#xff1a;J哥 来源&#xff1a;菜J学Python 项目背景 网上PDF转换工具眼花缭乱&#xff0c;选择困难症&#xff0c;有些甚至还收费&#xff1b;直接以其他格式打开PDF效果一般较差&#xff1b;有些小可爱通过复…

KDD 2022 | 量化交易相关论文(附论文链接)

写在前面 ACM SIGKDD国际会议&#xff08;简称 KDD&#xff09;是由ACM的数据挖掘及知识发现专委会主办的数据挖掘研究领域的顶级年会&#xff0c;属于CCF A类会议。第28届KDD会议于2022于8月14日至18日在美国华盛顿举行。KDD 会议包含 Research 和 Applied Data Science 两个 …

分享|数智化转型咨询赋能白皮书2021(附PDF)

在创世界一流“力量大厦”发展战略指引下&#xff0c;中国移动凝聚全集团数智化转型相关能力&#xff0c;发挥公司技术、生态、经验势能优势&#xff0c;围绕“能力即服务”价值实现体系&#xff0c;系统性打造中国移动特色的“1357 数智化转型赋能方法论”&#xff0c;即1个核…

ERP_课程论文(hunnu)

目录 一、概述 1.本课程的内容 2.企业情况 二、主要内容&#xff08;三年对战&#xff09; 1.第一年规划 2.第二年规划 3.第三年规划 三、结语 1.学习心得 &#xff08;1&#xff09; 定量分析 &#xff08;2&#xff09; 租买产房 &#xff08;3&#xff09; 建设…

用户体验的要素pdf_用户运营思路(35份)

用户运营思路(35份) ├1 用户画像指导用户精细化运营.pdf ├2 2019用户生命周期运营白皮书-京东尼尔森-2019.11-57页.pdf ├3 从战术到战略&#xff0c;如何获取&运营早期用户.doc ├4 社群变现的道与术&#xff1a;私域流量&用户运营.pdf ├5 易观-智能用户…