feat: implement native video player for IPTV live TV, VOD, and series with media_kit, including related UI and settings.

This commit is contained in:
Michael committed 2025-12-20 16:26:11 +01:00
1 parent b249074db1
commit b60efd6acb
5 files changed
+101 -60

No files matched your search

@@ -307,19 +307,27 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen>
if (key == LogicalKeyboardKey.arrowDown ||
key == LogicalKeyboardKey.channelDown) {
if (widget.streamType == StreamType.live) {
_playPrevious();
_onUserInteraction();
// Only switch with arrows if controls are hidden
if (key == LogicalKeyboardKey.channelDown || !_showControls) {
_playPrevious();
_onUserInteraction();
return true;
}
}
return true;
return false; // Let focus system handle it if controls are visible
}
if (key == LogicalKeyboardKey.arrowUp ||
key == LogicalKeyboardKey.channelUp) {
if (widget.streamType == StreamType.live) {
_playNext();
_onUserInteraction();
// Only switch with arrows if controls are hidden
if (key == LogicalKeyboardKey.channelUp || !_showControls) {
_playNext();
_onUserInteraction();
return true;
}
}
return true;
return false; // Let focus system handle it if controls are visible
}
if (widget.streamType != StreamType.live) {
@@ -524,15 +532,6 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen>
style: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold)),
const Spacer(),
// Aspect Ratio Toggle
TVFocusable(
focusNode: FocusNode(),
onPressed: _cycleAspectRatio,
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: Icon(Icons.aspect_ratio, color: Colors.white70),
),
),
const SizedBox(width: 16),
Text(
_currentTime,
@@ -132,8 +132,16 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen>
// Enable software decoding fallback if hardware fails (handled by mpv usually, but ensuring 'auto' helps)
final decoderMode = ref.read(mobileSettingsProvider).decoderMode;
final deinterlace = ref.read(mobileSettingsProvider).deinterlace;
(_player.platform as dynamic)?.setProperty('hwdec', decoderMode);
debugPrint('MediaKitPlayer: Decoder Mode set to $decoderMode');
(_player.platform as dynamic)
?.setProperty('deinterlace', deinterlace ? 'yes' : 'no');
// Performance & Scaling Fixes for Android
(_player.platform as dynamic)?.setProperty('opengl-pbo', 'yes');
(_player.platform as dynamic)?.setProperty('video-unscaled', 'no');
debugPrint(
'MediaKitPlayer: Decoder Mode set to $decoderMode, Deinterlace: $deinterlace');
// ============ PERFORMANCE 3.0 (ANTI MICRO-COUPURE PROFILE) ============
// Tuned to eliminate micro-stuttering during live TV playback
@@ -200,16 +208,16 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen>
);
// Prevent stalls (readahead already set above)
(_player.platform as dynamic)?.setProperty('hr-seek', 'yes');
(_player.platform as dynamic)?.setProperty('hr-seek-framedrop', 'yes');
(_player.platform as dynamic)
?.setProperty('hr-seek', 'yes'); // High-res seeking
?.setProperty('vd-lavc-dr', 'yes'); // Direct rendering
(_player.platform as dynamic)
?.setProperty('hr-seek-framedrop', 'yes'); // Drop frames to catch up
// Frame dropping policy - prefer dropping frames over stuttering
?.setProperty('vd-lavc-fast', 'yes'); // Fast decoding
(_player.platform as dynamic)
?.setProperty('vd-lavc-threads', '4'); // Multithreading
(_player.platform as dynamic)?.setProperty(
'framedrop',
'decoder+vo',
); // Allow frame drops at decoder and video output
'vd-lavc-skiploopfilter', 'all'); // Skip loop filter for performance
// ============ AUDIO CODEC SUPPORT FOR VOD ============
// V3: Explicit LAVC Downmix & Audiotrack
@@ -831,21 +839,31 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen>
}
// Up Arrow - Previous channel (Live only)
if (key == LogicalKeyboardKey.arrowUp) {
if (key == LogicalKeyboardKey.arrowUp ||
key == LogicalKeyboardKey.channelUp) {
if (widget.streamType == StreamType.live && widget.channels != null) {
_playPrevious();
if (key == LogicalKeyboardKey.channelUp || !_showControls) {
_playPrevious();
return true;
}
}
return true;
return false; // Let focus handle navigation if controls shown
}
// Down Arrow - Next channel (Live) or Cycle Audio (VOD)
if (key == LogicalKeyboardKey.arrowDown) {
if (key == LogicalKeyboardKey.arrowDown ||
key == LogicalKeyboardKey.channelDown) {
if (widget.streamType == StreamType.live && widget.channels != null) {
_playNext();
} else if (widget.streamType != StreamType.live) {
if (key == LogicalKeyboardKey.channelDown || !_showControls) {
_playNext();
return true;
}
} else if (widget.streamType != StreamType.live &&
key == LogicalKeyboardKey.arrowDown) {
_cycleAudioTrack();
return true;
}
return true;
return false; // Let focus handle navigation if controls shown
}
// Cycle Aspect Ratio - secret key 'A' or digit 1
@@ -1288,23 +1306,6 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen>
),
),
),
const SizedBox(width: 32),
// Aspect Ratio Toggle
TVFocusable(
focusNode:
FocusNode(), // Temporary node or add to state if needed
onPressed: _cycleAspectRatio,
onFocus: _resetControlsTimer,
borderRadius: BorderRadius.circular(50),
child: IconButton(
icon: const Icon(Icons.aspect_ratio,
color: Colors.white, size: 36),
onPressed: _cycleAspectRatio,
tooltip: 'Format d\'image',
),
),
],
),
),
@@ -431,20 +431,38 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
void _playChannel(BuildContext context, Channel channel,
List<Channel> channels, PlaylistConfig playlist, int index) async {
// Unified Player Strategy: Use LitePlayer (ExoPlayer) for Live TV (Stability)
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LitePlayerScreen(
streamId: channel.streamId,
title: channel.name,
playlist: playlist,
streamType: StreamType.live,
channels: channels, // Pass full channel list for zapping
initialIndex: index,
final settings = ref.read(mobileSettingsProvider);
final useNative = settings.playerEngine == 'ultra';
if (useNative) {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NativePlayerScreen(
streamId: channel.streamId,
title: channel.name,
playlist: playlist,
streamType: StreamType.live,
channels: channels, // Pass full channel list for zapping
initialIndex: index,
),
),
),
);
);
} else {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LitePlayerScreen(
streamId: channel.streamId,
title: channel.name,
playlist: playlist,
streamType: StreamType.live,
channels: channels, // Pass full channel list for zapping
initialIndex: index,
),
),
);
}
// When returning from player, set flag to prevent PopScope from going back to categories
if (mounted) {
@@ -145,6 +145,18 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
},
),
_buildSettingItem(
icon: Icons.line_weight,
title: 'Désentrelacement',
subtitle: settings.deinterlace
? 'Activé (Recommandé pour TV en direct)'
: 'Désactivé',
value: settings.deinterlace ? 'Oui' : 'Non',
onTap: () => ref
.read(mobileSettingsProvider.notifier)
.toggleDeinterlace(!settings.deinterlace),
),
_buildSettingItem(
icon: Icons.speed,
title: 'Buffer (Cache)',
@@ -13,6 +13,7 @@ class MobileSettings {
final String decoderMode; // 'auto', 'mediacodec' (HW), 'no' (SW)
final String playerEngine; // 'ultra' (MPV), 'lite' (ExoPlayer)
final String aspectRatioMode; // 'contain', 'cover', 'fill'
final bool deinterlace;
final int bufferDuration; // seconds, 0 = auto
const MobileSettings({
@@ -24,6 +25,7 @@ class MobileSettings {
this.decoderMode = 'auto',
this.playerEngine = 'ultra',
this.aspectRatioMode = 'contain',
this.deinterlace = false,
this.bufferDuration = 0,
});
@@ -36,6 +38,7 @@ class MobileSettings {
String? decoderMode,
String? playerEngine,
String? aspectRatioMode,
bool? deinterlace,
int? bufferDuration,
}) {
return MobileSettings(
@@ -47,6 +50,7 @@ class MobileSettings {
decoderMode: decoderMode ?? this.decoderMode,
playerEngine: playerEngine ?? this.playerEngine,
aspectRatioMode: aspectRatioMode ?? this.aspectRatioMode,
deinterlace: deinterlace ?? this.deinterlace,
bufferDuration: bufferDuration ?? this.bufferDuration,
);
}
@@ -108,6 +112,7 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
_box?.get('playerEngine', defaultValue: 'ultra') as String?;
final aspectRatioMode =
_box?.get('aspectRatioMode', defaultValue: 'contain') as String?;
final deinterlace = _box?.get('deinterlace', defaultValue: false) as bool?;
final buffer = _box?.get('bufferDuration', defaultValue: 0) as int?;
state = MobileSettings(
@@ -119,6 +124,7 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
decoderMode: decoderMode ?? 'auto',
playerEngine: playerEngine ?? 'ultra',
aspectRatioMode: aspectRatioMode ?? 'contain',
deinterlace: deinterlace ?? false,
bufferDuration: buffer ?? 0,
);
}
@@ -163,6 +169,11 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
_box?.put('aspectRatioMode', mode);
}
void toggleDeinterlace(bool value) {
state = state.copyWith(deinterlace: value);
_box?.put('deinterlace', value);
}
void setBufferDuration(int seconds) {
state = state.copyWith(bufferDuration: seconds);
_box?.put('bufferDuration', seconds);