播放器修改,功能完善
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/core/logging/i_logger_service.dart';
|
||||
import 'package:maibu_satabot_v2/core/protocol/packet_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/domain/entities/running_status_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_state.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../connectivity/presentation/bloc/connectivity_cubit.dart';
|
||||
import '../../domain/entities/machine_control_entity.dart';
|
||||
import '../../domain/repositories/remote_control_repository.dart';
|
||||
|
||||
class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
final RemoteControlRepository _repository;
|
||||
final ConnectivityCubit connectivityCubit;
|
||||
|
||||
// 定时器与流订阅管理
|
||||
Timer? _timer;
|
||||
StreamSubscription<RunningStatusEntity>? _statusSubscription;
|
||||
StreamSubscription<PacketEntity>? _responseSubscription;
|
||||
|
||||
RemoteControlCubit(this._repository)
|
||||
RemoteControlCubit(this._repository,this.connectivityCubit)
|
||||
: super(
|
||||
RemoteControlState(
|
||||
controlEntity: MachineControlEntity(),
|
||||
@@ -153,6 +157,32 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
void toggleLeftPip() => emit(state.copyWith(showLeftPip: !state.showLeftPip));
|
||||
void toggleRightPip() => emit(state.copyWith(showRightPip: !state.showRightPip));
|
||||
|
||||
void toggleTopLeftExpand() {
|
||||
emit(state.copyWith(topRightIsExpanded: !state.topRightIsExpanded));
|
||||
}
|
||||
|
||||
void toggleObstacleRecognition() {
|
||||
emit(state.copyWith(obstacleRecognitionFlag: !state.obstacleRecognitionFlag));
|
||||
}
|
||||
|
||||
void initVideoUrls(String main, String ai) {
|
||||
emit(state.copyWith(
|
||||
mainStreamUrl: main,
|
||||
aiStreamUrl: ai,
|
||||
isVideoEnabled: true,
|
||||
));
|
||||
}
|
||||
|
||||
void disposeVideo() {
|
||||
emit(state.copyWith(
|
||||
mainStreamUrl: "",
|
||||
aiStreamUrl: "",
|
||||
isVideoEnabled: false,
|
||||
obstacleRecognitionFlag: false,
|
||||
));
|
||||
sl<ILoggerService>().log("Cubit: 视频地址已置空,准备断开连接");
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 4. 销毁与清理 (Cleanup)
|
||||
// ==========================================
|
||||
@@ -164,4 +194,5 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
_responseSubscription?.cancel();
|
||||
return super.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class RemoteControlState extends Equatable {
|
||||
// --- 安全与锁定 ---
|
||||
final bool isEmergency; // 紧急停止状态
|
||||
final bool isLocked; // 控制锁定状态
|
||||
final String obstacleFlag; // 障碍物标志位文字 (对应 Entity 里的 0/1)
|
||||
final String obstacleFlag; // 障碍物标志位文字(这是机器传过来的) (对应 Entity 里的 0/1)
|
||||
|
||||
// --- 网络与连接 ---
|
||||
final int ping; // 延迟/心跳
|
||||
@@ -28,6 +28,12 @@ class RemoteControlState extends Equatable {
|
||||
// --- UI 视图配置 ---
|
||||
final bool showLeftPip; // 左侧画中画显示
|
||||
final bool showRightPip; // 右侧画中画显示
|
||||
final bool topRightIsExpanded; // 顶部右侧按钮展开状态
|
||||
final bool obstacleRecognitionFlag; // 障碍物识别标志位(这是UI显示的)
|
||||
|
||||
final String mainStreamUrl;
|
||||
final String aiStreamUrl;
|
||||
final bool isVideoEnabled;
|
||||
|
||||
const RemoteControlState({
|
||||
this.status = RemoteControlStatus.initial,
|
||||
@@ -44,10 +50,15 @@ class RemoteControlState extends Equatable {
|
||||
this.errorMessage,
|
||||
this.showLeftPip = true,
|
||||
this.showRightPip = true,
|
||||
this.topRightIsExpanded = false,
|
||||
this.obstacleRecognitionFlag = false,
|
||||
this.mainStreamUrl = '',
|
||||
this.aiStreamUrl = '',
|
||||
this.isVideoEnabled = true
|
||||
});
|
||||
|
||||
// 辅助属性:判断当前是否具备物理驾驶条件
|
||||
bool get canDrive => hasPermission && !isEmergency && !isLocked;
|
||||
bool get canDrive => hasPermission && !isLocked;
|
||||
|
||||
RemoteControlState copyWith({
|
||||
RemoteControlStatus? status,
|
||||
@@ -64,6 +75,11 @@ class RemoteControlState extends Equatable {
|
||||
String? errorMessage,
|
||||
bool? showLeftPip,
|
||||
bool? showRightPip,
|
||||
bool? topRightIsExpanded,
|
||||
bool? obstacleRecognitionFlag,
|
||||
bool? isVideoEnabled,
|
||||
String? mainStreamUrl,
|
||||
String? aiStreamUrl
|
||||
}) {
|
||||
return RemoteControlState(
|
||||
status: status ?? this.status,
|
||||
@@ -80,6 +96,11 @@ class RemoteControlState extends Equatable {
|
||||
errorMessage: errorMessage ?? this.errorMessage,
|
||||
showLeftPip: showLeftPip ?? this.showLeftPip,
|
||||
showRightPip: showRightPip ?? this.showRightPip,
|
||||
topRightIsExpanded: topRightIsExpanded ?? this.topRightIsExpanded,
|
||||
obstacleRecognitionFlag: obstacleRecognitionFlag ?? this.obstacleRecognitionFlag,
|
||||
isVideoEnabled: isVideoEnabled ?? this.isVideoEnabled,
|
||||
mainStreamUrl: mainStreamUrl ?? this.mainStreamUrl,
|
||||
aiStreamUrl: aiStreamUrl ?? this.aiStreamUrl
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,5 +120,10 @@ class RemoteControlState extends Equatable {
|
||||
errorMessage,
|
||||
showLeftPip,
|
||||
showRightPip,
|
||||
topRightIsExpanded,
|
||||
obstacleRecognitionFlag,
|
||||
isVideoEnabled,
|
||||
mainStreamUrl,
|
||||
aiStreamUrl
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user