Skip to content

Commit

Permalink
fix: Display the correct video resolution to the user (bluecherrydvr#233
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bdlukaa authored Mar 5, 2024
2 parents fd9e7b0 + b9a9d9a commit 3fbf813
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 5 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ class _UnityAppState extends State<UnityApp>
await Future.microtask(() async {
for (final player in UnityVideoPlayerInterface.players.toList()) {
debugPrint('Disposing player ${player.hashCode}');
await player.dispose();
try {
await player.dispose();
} catch (e) {
debugPrint('Error disposing player: $e');
}
}
});
windowManager.destroy();
Expand Down
4 changes: 3 additions & 1 deletion lib/screens/layouts/video_status_label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ class _DeviceVideoInfo extends StatelessWidget {
_buildTextSpan(
context,
title: loc.resolution,
data: '${device.resolutionX}x${device.resolutionY}',
data: '${video.player.width ?? device.resolutionX}'
'x'
'${video.player.height ?? device.resolutionY}',
),
_buildTextSpan(context, title: loc.fps, data: '${video.fps}'),
_buildTextSpan(
Expand Down
9 changes: 6 additions & 3 deletions lib/utils/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ class UnityPlayers with ChangeNotifier {
RenderingQuality.p480 => UnityVideoQuality.p480,
RenderingQuality.p360 => UnityVideoQuality.p360,
RenderingQuality.p240 => UnityVideoQuality.p240,
RenderingQuality.automatic =>
UnityVideoQuality.qualityForResolutionY(device.resolutionY),
RenderingQuality.automatic => null,
},
onReload: setSource,
title: device.fullName,
Expand All @@ -139,7 +138,11 @@ class UnityPlayers with ChangeNotifier {
static Future<void> releaseDevice(String deviceUUID) async {
debugPrint('Releasing device $deviceUUID. ${players[deviceUUID]}');
_reloadable.remove(deviceUUID);
await players[deviceUUID]?.dispose();
try {
await players[deviceUUID]?.dispose();
} catch (e) {
debugPrint('Error disposing player: $e');
}
players.remove(deviceUUID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ class UnityVideoPlayerMediaKit extends UnityVideoPlayer {
_fps = double.parse(fps);
_fpsStreamController.add(_fps);
})
..observeProperty('dwidth', (width) async {
..observeProperty('width', (width) async {
debugPrint('display width: $width');
this.width = int.tryParse(width);
if (this.width != null && this.width! > maxSize.width) {
maxSize = Size(this.width!.toDouble(), maxSize.height);
}
})
..observeProperty('dheight', (height) async {
..observeProperty('height', (height) async {
debugPrint('display height: $height');
this.height = int.tryParse(height);
if (this.height != null && this.height! > maxSize.height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,6 @@ enum UnityVideoQuality {
final bool isHD;

const UnityVideoQuality._({required this.resolution, this.isHD = false});

/// Returns the video quality for the video height
static UnityVideoQuality qualityForResolutionY(int? height) {
return switch (height) {
1080 => p1080,
720 => p720,
480 => p480,
360 => p360,
240 => p240,
_ => p480,
};
}
}

/// How to handle late video streams.
Expand Down Expand Up @@ -319,7 +307,7 @@ abstract class UnityVideoPlayer with ChangeNotifier {
/// The [onReload] parameter is called when the video needs to be reloaded.
/// It is usually used when the image has been old for a while.
static UnityVideoPlayer create({
UnityVideoQuality quality = UnityVideoQuality.p360,
UnityVideoQuality? quality,
bool enableCache = false,
RTSPProtocol? rtspProtocol,
Future<String>? fallbackUrl,
Expand All @@ -328,8 +316,8 @@ abstract class UnityVideoPlayer with ChangeNotifier {
LateVideoBehavior lateVideoBehavior = LateVideoBehavior.automatic,
}) {
return UnityVideoPlayerInterface.instance.createPlayer(
width: quality.resolution.width.toInt(),
height: quality.resolution.height.toInt(),
width: quality?.resolution.width.toInt(),
height: quality?.resolution.height.toInt(),
enableCache: enableCache,
rtspProtocol: rtspProtocol,
title: title,
Expand Down Expand Up @@ -362,6 +350,9 @@ abstract class UnityVideoPlayer with ChangeNotifier {

int? width;
int? height;
Size? get resolution => width != null && height != null
? Size(width!.toDouble(), height!.toDouble())
: null;
String? error;

UnityVideoQuality? quality;
Expand Down

0 comments on commit 3fbf813

Please sign in to comment.