Merge branch 'fix-live-tv-never-prompt-to-watch-from-start-of-recording'

This commit is contained in:
edde746
2026-04-06 04:12:44 +02:00
2 changed files with 33 additions and 7 deletions
+2 -1
View File
@@ -1127,7 +1127,8 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
final watchFromStart = await _showWatchFromStartDialog(effectiveStart, nowEpoch);
if (!mounted) return;
if (watchFromStart == true) {
offsetSeconds = max(_programBeginsAt! - _captureBuffer!.startedAt.round(), 0);
final programBeginsAtOffset = _programBeginsAt! - _captureBuffer!.startedAt.round();
offsetSeconds = max(programBeginsAtOffset, _captureBuffer!.seekStartSeconds.round());
}
}
}
+31 -6
View File
@@ -2575,14 +2575,34 @@ class PlexClient {
final subList = subscriptions is List ? subscriptions : subscriptions is Map ? [subscriptions] : null;
if (subList != null && subList.isNotEmpty) {
final sub = subList.first as Map<String, dynamic>;
final timeline = sub['Timeline'];
// Safely extract the first element if it's a list, or the map itself
final op = timeline is List
? (timeline.isNotEmpty ? timeline.first : null)
: (timeline is Map ? timeline : null);
if (op is Map) {
if (op['Metadata'] case [Map firstMetadata, ...]) {
if (firstMetadata['Media'] case [Map firstMedia, ...]) {
final rawBeginsAt = firstMedia['beginsAt'];
beginsAt = switch (rawBeginsAt) {
num n => n.toInt(),
String s => int.tryParse(s),
_ => null,
};
appLogger.d('beginsAt=$beginsAt');
}
}
}
final ops = sub['MediaGrabOperation'];
final opList = ops is List ? ops : ops is Map ? [ops] : null;
if (opList != null && opList.isNotEmpty) {
final op = opList.first as Map<String, dynamic>;
final rawBeginsAt = op['beginsAt'];
beginsAt = rawBeginsAt is num
? rawBeginsAt.toInt()
: rawBeginsAt is String ? int.tryParse(rawBeginsAt) : null;
final nested = op['Metadata'];
if (nested is Map<String, dynamic>) {
metadataJson = nested;
@@ -2629,13 +2649,18 @@ class PlexClient {
}
// beginsAt may also be on the Media items (not just the GrabOperation)
// This value is the start of the requested stream, not the current program. So it will effectively be the current time
if (beginsAt == null) {
final media = metadataJson['Media'];
if (media is List && media.isNotEmpty) {
final firstMedia = media.first;
if (firstMedia is Map<String, dynamic>) {
final raw = firstMedia['beginsAt'];
beginsAt = raw is num ? raw.toInt() : raw is String ? int.tryParse(raw) : null;
final rawBeginsAt = firstMedia['beginsAt'];
beginsAt = switch (rawBeginsAt) {
num n => n.toInt(),
String s => int.tryParse(s),
_ => null,
};
}
}
}