详细问题描述
按照官方文档写了简单的直播推流测试界面
<template>
<view style="height: 1000px;background-color: #007AFF;">
<live-pusher id='livePusher1' class="livePusher" ref="livePusher1" :url="pusherUrl" :mode="quality" :muted="muted"
:enable-camera="enableCamera" :auto-focus="autoFocus" :beauty="beauty" :whiteness="whiteness" aspect="9:16"
postition="absolute" @statechange="statechange" @netstatus="netstatus" @error="error" style="width: 100%;height: 500px;"></live-pusher>
<view class="allBtn">
<button class="btn" @click="start">开始推流</button>
<button class="btn" @click="pause">暂停推流</button>
<button class="btn" @click="resume">恢复推流</button>
<button class="btn" @click="stop">停止推流</button>
<button class="btn" @click="snapshot">快照</button>
<button class="btn" @click="beauty">美颜</button>
<button class="btn" @click="startPreview">开启摄像头预览</button>
<button class="btn" @click="stopPreview">关闭摄像头预览</button>
<button class="btn" @click="switchCamera">切换摄像头</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
fil: true,
pusherUrl: 'rtmp://livepush.huahualive.net/live/dddd', //推流地址,支持RTMP协议。
beauty: 0, //美颜,取值范围 0-9(iOS取值范围为1),0 表示关闭
whiteness: 0, //美白,取值范围 0-9(iOS取值范围为1),0 表示关闭
quality: 'HD', //推流视频模式,可取值:SD(标清),HD(高清), FHD(超清)
muted: true, //是否静音
height: '100px', //高度
enableCamera: true, //开启摄像头
autoFocus: true, //自动聚集
}
},
onReady() {
this.context = uni.createLivePusherContext("livePusher1", this);
console.log(this.$refs.livePusher1.attr)
this.height = uni.getSystemInfoSync().windowHeight + 'px';
if (uni.getSystemInfoSync().platform == "android") {
this.beauty = 1;
this.whiteness = 2;
}
if (uni.getSystemInfoSync().platform == "ios") {
this.beauty = 0.1;
this.whiteness = 0.2;
}
},
methods: {
//状态变化事件
statechange(e) {
console.log("状态变化:" + JSON.stringify(e));
},
//网络状态通知事件
netstatus(e) {
console.log("网络状态通知:" + JSON.stringify(e));
},
//渲染错误事件
error(e) {
console.log("错误:" + JSON.stringify(e));
},
start: function() {
this.context.start({
success: (a) => {
console.log("开始推流:" + JSON.stringify(a));
},
fail: (b) => {
console.log(a);
}
});
},
close: function() {
this.context.close({
success: (a) => {
console.log("关闭推流:" + JSON.stringify(a));
}
});
},
snapshot: function() {
this.context.snapshot({
success: (e) => {
console.log("快照:" +JSON.stringify(e));
}
});
},
resume: function() {
this.context.resume({
success: (a) => {
console.log("恢复推流:" + JSON.stringify(a));
}
});
},
pause: function() {
this.context.pause({
success: (a) => {
console.log("暂停推流:" + JSON.stringify(a));
}
});
},
stop: function() {
this.context.stop({
success: (a) => {
console.log("停止推流:" + JSON.stringify(a));
}
});
},
switchCamera: function() {
this.context.switchCamera({
success: (a) => {
console.log("切换摄像头:" + JSON.stringify(a));
}
});
},
startPreview: function() {
this.context.startPreview({
success: (a) => {
console.log("livePusher.startPreview:" + JSON.stringify(a));
}
});
},
stopPreview: function() {
this.context.stopPreview({
success: (a) => {
console.log("livePusher.stopPreview:" + JSON.stringify(a));
}
});
},
}
}
</script>
<style>
.allBtn {
position: fixed;
bottom: 0;
left: 0;
flex-direction: row;
flex-wrap: wrap;
width: 750upx;
}
.btn {
margin: 0 10upx;
}
</style>
[内容]
点击执行 startPreview 时,报错误
[ERROR] : thirdScriptError
10:30:37.987 this.context.startPreview is not a function. (In 'this.context.startPreview', 'this.context.startPreview' is undefined); [Component] Event Handler Error @ pages/index/index#handleEvent
[步骤]
[结果]
[期望]
[如果语言难以表述清晰,拍一个视频或截图,有图有真相]
IDE运行环境说明
[HBuilderX]
[IDE版本号]
2.4.2.20191115
[windows版本号]
[mac版本号]
10.13.6
uni-app运行环境说明
[安卓app,真机模拟,华为p30 pro]
[运行端版本号]
[项目是cli创建的还是HBuilderX创建的?如果是cli创建的,请更新到最新版cli再试]
[编译模式是老模板模式还是新的自定义组件模式?]
App运行环境说明
[Android版本号]
[iOS版本号]
[手机型号]
[模拟器型号]
附件
[IDE问题请提供HBuilderX运行日志。菜单帮助-查看运行日志,点右键打开文件所在目录,将log文件压缩成zip包上传]
[App问题请提供可重现问题的代码片段,你补充的细一点,问题就解决的快一点]
[App安装包或H5地址]
[可重现代码片段]
联系方式
[QQ] 164059655
6 个回复
1***@qq.com
解决办法
修改manifest.json文件。
manifest.json -> "App常用其它设置" -> “编译模式” -> 去掉V3编译器
1***@qq.com
楼上方法还是不行,我也遇到了
罗根 - 全栈工程师
我的直接就报Can not find
livePusher1
错误,这是怎么回事,急急急急!3***@qq.com
解决了吗
天一呦
解决了吗?
2***@qq.com
同问,解决了吗?