- 发布:2023-11-10 12:05
- 更新:2023-11-10 12:05
- 阅读:174
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 22H2
HBuilderX类型: 正式
HBuilderX版本号: 3.8.12
手机系统: 全部
手机厂商: 华为
页面类型: nvue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
操作步骤:
<template>
<view>
<live-pusher id='livePusher' ref="livePusher" class="livePusher" :url="rtmpPush"
enable-mic="true" mode="FHD" :muted="false" :enable-camera="true" :auto-focus="true"
beauty="1" whiteness="2"
aspect="9:16" @statechange="statechange" @netstatus="netstatus" @error = "error"
></live-pusher>
<button class="btn" @click="start">开始推流</button>
<button class="btn" @click="pause">暂停推流</button>
<button class="btn" @click="resume">resume</button>
<button class="btn" @click="stop">停止推流</button>
<button class="btn" @click="snapshot">快照</button>
<button class="btn" @click="startPreview">开启摄像头预览</button>
<button class="btn" @click="stopPreview">关闭摄像头预览</button>
<button class="btn" @click="switchCamera">切换摄像头2</button>
</view>
</template>
<script>
import {
getPushUrlAndPullUrl, // 寺院端直播 录播
} from "@/apis/index.js";
export default {
data() {
return {
rtmpPush: '',
id: ''
}
},
onLoad(options) {
var that = this
console.log(options)
that.id = options.id
this.getUrl()
},
onReady() {
// 注意:需要在onReady中 或 onLoad 延时
this.context = uni.createLivePusherContext("livePusher", this);
},
methods: {
getUrl() {
var that = this
console.log('请求')
getPushUrlAndPullUrl({
orderId: that.id,
pullAllPush: 1
}).then(res => {
// 推流地址
that.rtmpPush = res.data.rtmpPush
console.log('获取推流地址了', res.data.rtmpPush)
// that.startTimer();
})
},
statechange(e) {
console.log("statechange:" + JSON.stringify(e));
},
netstatus(e) {
console.log("netstatus:" + JSON.stringify(e));
},
error(e) {
console.log("error:" + JSON.stringify(e));
},
start: function() {
console.log('开始推流')
this.context.start({
success: (a) => {
uni.showToast({
title: "livePusher.start:" + JSON.stringify(a),
icon: "none"
})
console.log("livePusher.start:" + JSON.stringify(a));
}, fail: (a) => {
uni.showToast({
title: "livePusher.start失败:" + JSON.stringify(a),
icon: "none"
})
}, complete: (a) => {
uni.showToast({
title: "livePusher.start统调:" + JSON.stringify(a),
icon: "none"
})
}
});
},
close: function() {
this.context.close({
success: (a) => {
console.log("livePusher.close:" + JSON.stringify(a));
}
});
},
snapshot: function() {
this.context.snapshot({
success: (e) => {
console.log(JSON.stringify(e));
uni.saveImageToPhotosAlbum({
filePath: e.message.tempImagePath, //图片url
success: () => {
uni.showToast({
title: "分享图片已保存到相册",
icon: 'none',
duration: 2000
})
}
})
}
});
},
resume: function() {
this.context.resume({
success: (a) => {
console.log("livePusher.resume:" + JSON.stringify(a));
}
});
},
pause: function() {
this.context.pause({
success: (a) => {
console.log("livePusher.pause:" + JSON.stringify(a));
}
});
},
stop: function() {
this.context.stop({
success: (a) => {
console.log(JSON.stringify(a));
}
});
},
switchCamera: function() {
this.context.switchCamera({
success: (a) => {
console.log("livePusher.switchCamera:" + 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>
</style>
1.先创建一个推流
2.用播放器拉流
3.连上蓝牙耳机
4.拿着耳机和拉流手机 站远离推流手机然后发声
5.判断是否有声音 有 说明没问题 可以通过耳机发声 没有 就是推流手机 扬声器发声。
></live-pusher>
<button class="btn" @click="start">开始推流</button>
<button class="btn" @click="pause">暂停推流</button>
<button class="btn" @click="resume">resume</button>
<button class="btn" @click="stop">停止推流</button>
<button class="btn" @click="snapshot">快照</button>
<button class="btn" @click="startPreview">开启摄像头预览</button>
<button class="btn" @click="stopPreview">关闭摄像头预览</button>
<button class="btn" @click="switchCamera">切换摄像头2</button>
</view>
</template>
<script>
import {
getPushUrlAndPullUrl, // 寺院端直播 录播
} from "@/apis/index.js";
export default {
data() {
return {
rtmpPush: '',
id: ''
}
},
onLoad(options) {
var that = this
console.log(options)
that.id = options.id
this.getUrl()
},
onReady() {
// 注意:需要在onReady中 或 onLoad 延时
this.context = uni.createLivePusherContext("livePusher", this);
},
methods: {
getUrl() {
var that = this
console.log('请求')
getPushUrlAndPullUrl({
orderId: that.id,
pullAllPush: 1
}).then(res => {
// 推流地址
that.rtmpPush = res.data.rtmpPush
console.log('获取推流地址了', res.data.rtmpPush)
// that.startTimer();
})
},
statechange(e) {
console.log("statechange:" + JSON.stringify(e));
},
netstatus(e) {
console.log("netstatus:" + JSON.stringify(e));
},
error(e) {
console.log("error:" + JSON.stringify(e));
},
start: function() {
console.log('开始推流')
this.context.start({
success: (a) => {
uni.showToast({
title: "livePusher.start:" + JSON.stringify(a),
icon: "none"
})
console.log("livePusher.start:" + JSON.stringify(a));
}, fail: (a) => {
uni.showToast({
title: "livePusher.start失败:" + JSON.stringify(a),
icon: "none"
})
}, complete: (a) => {
uni.showToast({
title: "livePusher.start统调:" + JSON.stringify(a),
icon: "none"
})
}
});
},
close: function() {
this.context.close({
success: (a) => {
console.log("livePusher.close:" + JSON.stringify(a));
}
});
},
snapshot: function() {
this.context.snapshot({
success: (e) => {
console.log(JSON.stringify(e));
uni.saveImageToPhotosAlbum({
filePath: e.message.tempImagePath, //图片url
success: () => {
uni.showToast({
title: "分享图片已保存到相册",
icon: 'none',
duration: 2000
})
}
})
}
});
},
resume: function() {
this.context.resume({
success: (a) => {
console.log("livePusher.resume:" + JSON.stringify(a));
}
});
},
pause: function() {
this.context.pause({
success: (a) => {
console.log("livePusher.pause:" + JSON.stringify(a));
}
});
},
stop: function() {
this.context.stop({
success: (a) => {
console.log(JSON.stringify(a));
}
});
},
switchCamera: function() {
this.context.switchCamera({
success: (a) => {
console.log("livePusher.switchCamera:" + 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>
</style>
1.先创建一个推流
2.用播放器拉流
3.连上蓝牙耳机
4.拿着耳机和拉流手机 站远离推流手机然后发声
5.判断是否有声音 有 说明没问题 可以通过耳机发声 没有 就是推流手机 扬声器发声。
预期结果:
所有手机 都可以用耳机发声
所有手机 都可以用耳机发声
实际结果:
小部分手机可以 大部分不行
小部分手机可以 大部分不行
bug描述:
live-pusher直播推流时 连接蓝牙耳机 有些设备发声还是通过扬声器 没有通过耳机。
0 个回复