uniapp live-pusher + 腾讯云直播

直播端

html 复制代码
<live-pusher
			id="livePusher"
			ref="livePusher"
			class="livePusher"
			:url="src"
			:mode="mode"
			:enable-camera="enableCamera"
			:auto-focus="true"
			:device-position="position"
			:beauty="beauty"
			:whiteness="whiteness"
			aspect="9:16"
			@statechange="statechange"
			@netstatus="netstatus"
			@error="error"
			:style="'height: ' + windowHeight + 'px;'"
			style="width: 750rpx"
		></live-pusher>
javascript 复制代码
<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			windowHeight: 0,
			src: '',
			mode: 'FHD',
			enableCamera: true,
			position: 'front',
			beauty: 0,
			whiteness: 0,
			context: null,
			// 是否开始推流
			isStart: false,
			isPause: false,
		};
	},
	onLoad(options) {
		/* 叫后端返回,推流地址别加鉴权,加了鉴权出不来 */
		this.src = options.url;
	},
	onShow() {
		let res = uni.getSystemInfoSync();
		this.windowHeight = res.windowHeight;
		if (this.context) {
			this.resume();
		}
	},
	onReady() {
		this.context = uni.createLivePusherContext('livePusher', this);
		this.startPreview();
		// 开始推流
		this.start();
	},
	onBackPress(e) {
		if (e.from == 'backbutton') {
			this.back();
			return true;
		}
	},
	onUnload() {
		this.stop();
	},
	methods: {
		// 开始推流
		start() {
			this.context.start({
				success: (e) => {
					this.isStart = true;
					console.log('开始推流', e);
				},
				fail: (err) => {
					console.log('开始推流失败', err);
				}
			});
		},
		// 开启预览
		startPreview() {
			this.context.startPreview({
				success: (e) => {
					console.log('开启预览', e);
				}
			});
		},
		// 直播状态变化
		statechange(e) {
			console.log('直播状态变化', e);
		},
		// 直播网络变化
		netstatus(e) {
			console.log('直播网络变化', e);
		},
		error(e) {
			console.log('直播报错', e);
		},
		stop() {
			this.context.stop({
				success: () => {
					
				}
			});
		},
		// 继续推流
		resume() {
			this.context.resume({
				success: () => {
					this.isPause = false;
				}
			});
		},
		// 暂停推流
		pause() {
			this.context.pause({
				success: () => {
					this.isPause = true;
				}
			});
		},
		// 退出直播
		back() {
			uni.showModal({
				content: '是否要关闭直播间?',
				success: (res) => {
					if (res.cancel) {
						return;
					}
					this.stop();
				}
			});
		},
	}
};
</script>

腾讯云直播文档地址(发给后端就行---推流地址别加鉴权)

https://cloud.tencent.com/document/product/267/32833

观众端,拉流地址就让后端直接返回就行

其他代码就不贴了,涉及到我这边其他业务,你们不一定用得上,懒得贴

相关推荐
ct9787 分钟前
vue2 + vue3差异点
前端·javascript·vue.js
小徐_233317 分钟前
程序员每天盯屏 10 小时,我开始认真研究“专业编程屏”这件事
前端
悟空瞎说27 分钟前
Git 协作工作流详解:从个人单打独斗到规模化团队协同
前端·git
颜进强30 分钟前
20-Spec-Kit Tasks 是怎么把技术方案拆成可执行任务的?
前端·后端·ai编程
程序员鱼皮30 分钟前
Cursor 零基础实战教程,夯爆了!带你速通 6 大核心能力
前端·后端·ai编程
颜进强31 分钟前
14-Spec-Kit、SDD 和 OpenSpec 到底有什么区别?其实核心思想都一样:先写清楚,再让 AI 干活
前端·后端·ai编程
颜进强31 分钟前
16-Spec-Kit 是什么?先从整体流程机制讲起
前端·后端·ai编程
悟空瞎说34 分钟前
QML 集成 WebView 开发桌面内嵌浏览器实战
前端
Delicate41 分钟前
揭开JS深拷贝的底裤:从递归到循环引用的终极解法
javascript
前端与小赵1 小时前
快速生成安卓证书并打包生成安卓apk(保姆教程)
android·前端