Skip to content

Commit

Permalink
fix: video status label never reaches the loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Sep 28, 2023
1 parent 26f8b3a commit 7812a47
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
32 changes: 16 additions & 16 deletions lib/widgets/device_grid/video_status_label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class _VideoStatusLabelState extends State<VideoStatusLabel> {
String get _source => widget.video.player.dataSource!;
bool get isLive =>
widget.video.player.dataSource != null &&
// It is only LIVE if it starts with rtsp and isn't hsl
// It is only LIVE if it starts with rtsp or is hsl
(_source.startsWith('rtsp') ||
_source.contains('media/mjpeg.php') ||
_source.endsWith('index.m3u8'));
_source.endsWith('index.m3u8') /* hsl */);

_VideoLabel get status => widget.video.error != null
? _VideoLabel.error
Expand Down Expand Up @@ -213,14 +213,17 @@ class _DeviceVideoInfo extends StatelessWidget {

List<TextSpan> buildTextSpans(BuildContext context) {
final loc = AppLocalizations.of(context);

final name = _buildTextSpan(context, title: loc.device, data: device.name);
final server = _buildTextSpan(
context,
title: loc.server,
data: '${device.server.name} (${device.id})',
);
if (isLive) {
return [
_buildTextSpan(context, title: loc.device, data: device.name),
_buildTextSpan(
context,
title: loc.server,
data: '${device.server.name} (${device.id})',
),
name,
server,
_buildTextSpan(
context,
title: loc.ptzSupported,
Expand All @@ -241,16 +244,11 @@ class _DeviceVideoInfo extends StatelessWidget {
last: true,
),
];
} else {
} else if (event != null) {
// If not live, it is a recorded footage
assert(event != null);
return [
_buildTextSpan(context, title: loc.device, data: device.name),
_buildTextSpan(
context,
title: loc.server,
data: '${device.server.name} (${device.id})',
),
name,
server,
_buildTextSpan(
context,
title: loc.duration,
Expand All @@ -268,6 +266,8 @@ class _DeviceVideoInfo extends StatelessWidget {
last: true,
),
];
} else {
return [name, server];
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/widgets/error_warning.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ErrorWarning extends StatelessWidget {
const SizedBox(height: 8.0),
Text(
message.toUpperCase(),
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white70,
fontSize: 12.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,17 @@ abstract class UnityVideoPlayer {
}

void _onDurationUpdate(Duration duration) {
_lastImageTime = DateTime.now();
_isImageOld = false;
_oldImageTimer?.cancel();
_oldImageTimer = Timer(timerInterval, () {
// If the image is still the same after the interval, then it's old.
if (duration <= duration) {
_isImageOld = true;
}
});
if (duration > Duration.zero) {
_lastImageTime = DateTime.now();
_isImageOld = false;
_oldImageTimer?.cancel();
_oldImageTimer = Timer(timerInterval, () {
// If the image is still the same after the interval, then it's old.
if (duration <= duration) {
_isImageOld = true;
}
});
}
}

/// The current data source url
Expand Down

0 comments on commit 7812a47

Please sign in to comment.