This commit is contained in:
杨航
2025-11-25 16:25:35 +08:00
parent abe7998ccd
commit a0325bfb58
5 changed files with 248 additions and 39 deletions
+1
View File
@@ -488,6 +488,7 @@
"path": "pages/sparring/tip",
"style": {
"navigationBarTitleText": "AI陪练提示",
"disableSwipeBack": true,
"app-plus": {
"titleNView": false
}
+108 -6
View File
@@ -1,10 +1,112 @@
<template>
<!-- 通话 -->
<!-- <template>
<view>通话</view>
<live-pusher
url="rtmp://25.18.122.148:9605/voice_in/aa"
:enable-camera="true"
@statechange="statechange"
@netstatus="netstatus"
@error="errorFnc"
></live-pusher>
</template> -->
<template>
<view>
<video :is-live="true" :src="videoSrc" :autoplay="true"></video>
<live-pusher id="livePusher" ref="livePusher" class="livePusher" url="rtmp://25.18.122.148:9605/voice_in/aa" mode="SD" :muted="true" :enable-camera="false" :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">开启摄像头预览1</button>
<button class="btn" @click="stopPreview">关闭摄像头预览</button>
<button class="btn" @click="switchCamera">切换摄像头</button>
</view>
</template>
<script>
export default {
data() {
return {
videoSrc: 'rtmp://25.18.122.148:9605/voice_out/aa'
}
},
onReady() {
// 注意:需要在onReady中 或 onLoad 延时
this.context = uni.createLivePusherContext('livePusher', this)
},
methods: {
statechange(e) {
console.log('statechange:', e, JSON.stringify(e))
},
netstatus(e) {
console.log('netstatus:' + JSON.stringify(e))
},
error(e) {
console.log('error:' + JSON.stringify(e))
},
start: function () {
this.context.start({
success: a => {
console.log('livePusher.start:' + JSON.stringify(a))
}
})
},
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))
}
})
},
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>
<style></style>
+112
View File
@@ -0,0 +1,112 @@
<!-- <template>
<view>通话</view>
<live-pusher
url="rtmp://25.18.122.148:9605/voice_in/aa"
:enable-camera="true"
@statechange="statechange"
@netstatus="netstatus"
@error="errorFnc"
></live-pusher>
</template> -->
<template>
<div>
<video :is-live="true" :src="videoSrc" :autoplay="true"></video>
<live-pusher id="livePusher" ref="livePusher" class="livePusher" url="rtmp://25.18.122.148:9605/voice_in/aa" mode="SD" :muted="true" :enable-camera="false" :auto-focus="true" :beauty="1" whiteness="2" aspect="9:16" @statechange="statechange" @netstatus="netstatus" @error="error"></live-pusher>
<text class="btn" @click="start">开始推流</text>
<text class="btn" @click="pause">暂停推流</text>
<text class="btn" @click="resume">resume</text>
<text class="btn" @click="stop">停止推流</text>
<text class="btn" @click="snapshot">快照</text>
<text class="btn" @click="startPreview">开启摄像头预览1</text>
<text class="btn" @click="stopPreview">关闭摄像头预览</text>
<text class="btn" @click="switchCamera">切换摄像头</text>
</div>
</template>
<script>
export default {
data() {
return {
videoSrc: 'rtmp://25.18.122.148:9605/voice_out/aa'
}
},
onReady() {
// 注意:需要在onReady中 或 onLoad 延时
this.context = uni.createLivePusherContext('livePusher', this)
},
methods: {
statechange(e) {
console.log('statechange:', e, JSON.stringify(e))
},
netstatus(e) {
console.log('netstatus:' + JSON.stringify(e))
},
error(e) {
console.log('error:' + JSON.stringify(e))
},
start: function () {
this.context.start({
success: a => {
console.log('livePusher.start:' + JSON.stringify(a))
}
})
},
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))
}
})
},
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>
+26 -33
View File
@@ -7,7 +7,7 @@
<view class="sparring-detail-body">
<view class="top-box">
<view class="top-title">
<view class="back-icon" @click="common.navigateBack()"></view>
<view class="back-icon" @click="goBack()"></view>
{{ detailInfo.traName }}
</view>
<view class="top-desc">内容由AI生成</view>
@@ -100,7 +100,8 @@
import {
onShow,
onLoad,
onUnload
onUnload,
onBackPress
} from '@dcloudio/uni-app';
import common from '@/common/common';
import TouchBtn from './components/touchBtn.vue';
@@ -404,40 +405,31 @@
});
watchFlag.value += 1;
};
const goBack = () => {
if (detailInfo.value.traInterTyp === '01') {
overTalking()
}else{
common.navigateBack()
}
}
const overTalking = () => {
partnerChatReportTrigger({
execId: execId.value,
traId: traId.value,
talkingType: isPreview.value? 'preview' : 'practice'
}).then(res=>{
watchFlag.value = 1;
socketStore?.closeSocket();
changePlayItemId('')
pointAndBadgesRun(talkingType.value === '01'? '07': '08', null, ()=>{
common.navigateTo('/pages/sparring/result?isOver=1&traId=' + traId.value + '&execId=' + execId.value + '&type=' + talkingType.value + '&isPreview=' + (isPreview.value ?'1':''))
})
common.show('提示','确定结束陪练吗?').then(res => {
if (res) {
partnerChatReportTrigger({
execId: execId.value,
traId: traId.value,
talkingType: isPreview.value? 'preview' : 'practice'
}).then(res=>{
watchFlag.value = 1;
socketStore?.closeSocket();
changePlayItemId('')
pointAndBadgesRun(talkingType.value === '01'? '07': '08', null, ()=>{
common.navigateTo('/pages/sparring/result?isOver=1&traId=' + traId.value + '&execId=' + execId.value + '&type=' + talkingType.value + '&isPreview=' + (isPreview.value ?'1':''))
})
})
}
})
}
const getPointsList = (pointsList = [], badgesList = []) => {
pointsRef.value.open(pointsList, badgesList);
}
const badgeConfirm = (status, pointsList = [], badgesList = []) => {
badgeRef.value.close();
overTalking()
};
// 积分确认
const pointsConfirm = (status, pointsList = [], badgesList = []) => {
pointsRef.value.close();
if (badgesList.length > 0) {
nextTick(() => {
setTimeout(() => {
badgeRef.value.open(pointsList, badgesList);
}, 500);
});
}
};
const sendMessage = (data) => {
unref(SocketObj).send(data);
};
@@ -458,6 +450,7 @@
onMounted(() => {
// getDetailInfo()
})
onBackPress((res) => res.from === 'backbutton');
</script>
<style lang="scss" scoped>
+1
View File
@@ -76,6 +76,7 @@
"path": "pages/sparring/tip",
"style": {
"navigationBarTitleText": "AI陪练提示",
"disableSwipeBack": true,
"app-plus": {
"titleNView": false
}