安卓视频监控修改

master
denghaohaoya 2026-04-06 15:14:46 +08:00
parent 13ed350850
commit 4336af1e01
6 changed files with 169 additions and 28 deletions

View File

@ -2,8 +2,8 @@
"name" : "海驰24", "name" : "海驰24",
"appid" : "__UNI__7302921", "appid" : "__UNI__7302921",
"description" : "111", "description" : "111",
"versionName" : "1.2.1", "versionName" : "1.2.6",
"versionCode" : 102, "versionCode" : 106,
"transformPx" : false, "transformPx" : false,
"app-plus" : { "app-plus" : {
"usingComponents" : true, "usingComponents" : true,
@ -20,7 +20,7 @@
}, },
"distribute" : { "distribute" : {
"android" : { "android" : {
"minSdkVersion" : 21, "minSdkVersion" : 24,
"permissions" : [ "permissions" : [
"<!-- 扫码核心必要权限 -->", "<!-- 扫码核心必要权限 -->",
"<uses-permission android:name=\"android.permission.CAMERA\"/>", "<uses-permission android:name=\"android.permission.CAMERA\"/>",
@ -36,7 +36,7 @@
"<uses-permission android:name=\"android.permission.VIBRATE\"/>", "<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>" "<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>"
], ],
"abiFilters" : [ "armeabi-v7a" ] "abiFilters" : [ "arm64-v8a" ]
}, },
"ios" : { "ios" : {
"dSYMs" : false, "dSYMs" : false,

Binary file not shown.

View File

@ -14,10 +14,10 @@
} }
], ],
"integrateType": "aar", "integrateType": "aar",
"minSdkVersion": "21", "minSdkVersion": "24",
"permissions": [ "permissions": [
"android.permission.CHANGE_WIFI_MULTICAST_STATE" "android.permission.CHANGE_WIFI_MULTICAST_STATE"
] ]
} }
} }
} }

View File

@ -9,6 +9,9 @@
ref="ipcVideo" ref="ipcVideo"
class="ipc-video" class="ipc-video"
:uid="deviceUid" :uid="deviceUid"
:channel="currentChannel"
:streamType="currentStreamType"
:isNvr="isNvr"
@onStatus="onVideoStatusChange"> @onStatus="onVideoStatusChange">
</ry-ipc-video> </ry-ipc-video>
<!-- #endif --> <!-- #endif -->
@ -25,6 +28,35 @@
<text class="status-text">状态:{{ statusMsg }}</text> <text class="status-text">状态:{{ statusMsg }}</text>
</view> </view>
<!-- 设置区域 -->
<view class="settings-panel">
<view class="setting-row">
<text class="setting-label">设备类型:</text>
<view class="options-group">
<text class="option-btn" :class="!isNvr ? 'active-btn' : ''" @click="changeNvr(false)">单体(IPC)</text>
<text class="option-btn" :class="isNvr ? 'active-btn' : ''" @click="changeNvr(true)">主机(NVR)</text>
</view>
</view>
<view class="setting-row" v-if="isNvr">
<text class="setting-label">通道:</text>
<view class="options-group">
<text class="option-btn" :class="currentChannel === 0 ? 'active-btn' : ''" @click="changeChannel(0)">CH1</text>
<text class="option-btn" :class="currentChannel === 1 ? 'active-btn' : ''" @click="changeChannel(1)">CH2</text>
<text class="option-btn" :class="currentChannel === 2 ? 'active-btn' : ''" @click="changeChannel(2)">CH3</text>
<text class="option-btn" :class="currentChannel === 3 ? 'active-btn' : ''" @click="changeChannel(3)">CH4</text>
</view>
</view>
<view class="setting-row">
<text class="setting-label">清晰度:</text>
<view class="options-group">
<text class="option-btn" :class="currentStreamType === 1 ? 'active-btn' : ''" @click="changeStream(1)">高清</text>
<text class="option-btn" :class="currentStreamType === 2 ? 'active-btn' : ''" @click="changeStream(2)">标清</text>
</view>
</view>
</view>
<view class="controls"> <view class="controls">
<button class="btn btn-primary" @click="startPlay"><text class="btn-text">播放</text></button> <button class="btn btn-primary" @click="startPlay"><text class="btn-text">播放</text></button>
<button class="btn btn-warn" @click="stopPlay"><text class="btn-text">停止</text></button> <button class="btn btn-warn" @click="stopPlay"><text class="btn-text">停止</text></button>
@ -36,21 +68,72 @@
export default { export default {
data() { data() {
return { return {
deviceUid: 'HLTY020667DHKCD', // 默认使用你 Demo 里的测试 UID deviceUid: 'HLTY000072FFGGG', // 默认使用你 Demo 里的测试 UID
isPlaying: false, isPlaying: false,
statusMsg: '等待操作' statusMsg: '等待操作',
currentChannel: 0, // 0对应CH1, 1对应CH2...
currentStreamType: 1, // 1为高清(主码流)2为标清(子码流)
isNvr: false // 是否为 NVR 设备
} }
}, },
onLoad(options) { onLoad(options) {
if (options && options.uid) { if (options && options.uid) {
this.deviceUid = options.uid; this.deviceUid = options.uid;
} }
// 如果上个页面传了 isNvr 参数,这里可以接收
if (options && typeof options.isNvr !== 'undefined') {
// options.isNvr 通常传过来是字符串 'true' 或 'false'
this.isNvr = options.isNvr === 'true';
}
}, },
onUnload() { onUnload() {
// 页面卸载时停止播放,释放资源 // 页面卸载时停止播放,释放资源
this.stopPlay(); this.stopPlay();
}, },
methods: { methods: {
changeNvr(isNvrFlag) {
if (this.isNvr === isNvrFlag) return;
this.isNvr = isNvrFlag;
// 如果切换到了单体 IPC通道强制归 0
if (!isNvrFlag) {
this.currentChannel = 0;
}
// 如果正在播放,切换设备类型后需要完全重新连接并播放
if (this.isPlaying) {
this.stopPlay();
setTimeout(() => {
this.startPlay();
}, 1000); // 切换设备类型可能需要稍长一点的时间断开重连
}
},
changeChannel(ch) {
if (this.currentChannel === ch) return;
this.currentChannel = ch;
// 如果正在播放,切换通道后重新播放
if (this.isPlaying) {
this.stopPlay();
setTimeout(() => {
this.startPlay();
}, 500);
}
},
changeStream(type) {
if (this.currentStreamType === type) return;
this.currentStreamType = type;
// 如果有单独切换清晰度的方法可以调用,如果没有就重启播放
if (this.isPlaying) {
if (this.$refs.ipcVideo && typeof this.$refs.ipcVideo.setStreamType === 'function') {
this.$refs.ipcVideo.setStreamType(type);
} else {
this.stopPlay();
setTimeout(() => {
this.startPlay();
}, 500);
}
}
},
startPlay() { startPlay() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
if (this.$refs.ipcVideo) { if (this.$refs.ipcVideo) {
@ -84,31 +167,58 @@
// #endif // #endif
}, },
onVideoStatusChange(e) { onVideoStatusChange(e) {
console.log("视频状态改变:", e.detail); try {
// 根据我们在 Java 封装里写的 fireEventStatus 传回的 msg 显示 console.log("视频状态改变:", e);
if (e.detail) { // 根据我们在 Java 封装里写的 fireEventStatus 传回的 msg 显示
// 提取参数 if (e && e.detail) {
const status = e.detail.status; // 提取参数
const msg = e.detail.msg; const status = e.detail.status;
const msgParam = e.detail.msgParam; const msg = e.detail.msg;
const msgParam = e.detail.msgParam;
// 更新页面显示的文字状态 // 更新页面显示的文字状态
if (msg) { if (msg) {
this.statusMsg = msg; this.statusMsg = msg;
} }
// 处理特定的连接错误状态 // 捕获来自 Java 层主动抛出的原生崩溃错误
if (status === 'error' || msgParam === 7 || msgParam === 14) { if (status === 'error' && msg && msg.indexOf('原生启动崩溃') !== -1) {
uni.showModal({
title: '原生插件崩溃',
content: msg,
showCancel: false
});
this.isPlaying = false;
return;
}
// 处理特定的连接错误状态
if (status === 'error' || msgParam === 7 || msgParam === 14) {
uni.showToast({
title: msg ? msg : '摄像机离线,请检查设备网络',
icon: 'none',
duration: 3000
});
// 可以在这里做一些重置操作
this.isPlaying = false;
} else if (status === 'playing') {
this.isPlaying = true;
}
} else {
// 如果 e.detail 是空对象或者 undefined提示异常
console.error("收到空的状态事件:", e);
uni.showToast({ uni.showToast({
title: '摄像机离线,请检查设备网络', title: '收到空状态,原生可能发生异常',
icon: 'none', icon: 'none'
duration: 3000
}); });
// 可以在这里做一些重置操作
this.isPlaying = false;
} else if (status === 'playing') {
this.isPlaying = true;
} }
} catch (err) {
console.error("解析状态回调时发生前端异常:", err);
uni.showModal({
title: '前端回调解析异常',
content: err.toString(),
showCancel: false
});
} }
} }
} }
@ -181,4 +291,35 @@
color: #ffffff; color: #ffffff;
font-size: 30rpx; font-size: 30rpx;
} }
.settings-panel {
padding: 20rpx;
margin-top: 20rpx;
background-color: #ffffff;
}
.setting-row {
flex-direction: row;
align-items: center;
margin-bottom: 20rpx;
}
.setting-label {
font-size: 28rpx;
color: #333333;
width: 120rpx;
}
.options-group {
flex-direction: row;
flex: 1;
}
.option-btn {
padding: 10rpx 20rpx;
font-size: 26rpx;
color: #666666;
background-color: #f0f0f0;
border-radius: 8rpx;
margin-right: 20rpx;
}
.active-btn {
color: #ffffff;
background-color: #007aff;
}
</style> </style>