mirror of
https://github.com/R0m1k3/xtremobile.git
synced 2026-10-23 23:28:15 +02:00
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:
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 ||
|
if (key == LogicalKeyboardKey.arrowDown ||
|
||||||
key == LogicalKeyboardKey.channelDown) {
|
key == LogicalKeyboardKey.channelDown) {
|
||||||
if (widget.streamType == StreamType.live) {
|
if (widget.streamType == StreamType.live) {
|
||||||
_playPrevious();
|
// Only switch with arrows if controls are hidden
|
||||||
_onUserInteraction();
|
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 ||
|
if (key == LogicalKeyboardKey.arrowUp ||
|
||||||
key == LogicalKeyboardKey.channelUp) {
|
key == LogicalKeyboardKey.channelUp) {
|
||||||
if (widget.streamType == StreamType.live) {
|
if (widget.streamType == StreamType.live) {
|
||||||
_playNext();
|
// Only switch with arrows if controls are hidden
|
||||||
_onUserInteraction();
|
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) {
|
if (widget.streamType != StreamType.live) {
|
||||||
@@ -524,15 +532,6 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen>
|
|||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white, fontWeight: FontWeight.bold)),
|
color: Colors.white, fontWeight: FontWeight.bold)),
|
||||||
const Spacer(),
|
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),
|
const SizedBox(width: 16),
|
||||||
Text(
|
Text(
|
||||||
_currentTime,
|
_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)
|
// Enable software decoding fallback if hardware fails (handled by mpv usually, but ensuring 'auto' helps)
|
||||||
final decoderMode = ref.read(mobileSettingsProvider).decoderMode;
|
final decoderMode = ref.read(mobileSettingsProvider).decoderMode;
|
||||||
|
final deinterlace = ref.read(mobileSettingsProvider).deinterlace;
|
||||||
(_player.platform as dynamic)?.setProperty('hwdec', decoderMode);
|
(_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) ============
|
// ============ PERFORMANCE 3.0 (ANTI MICRO-COUPURE PROFILE) ============
|
||||||
// Tuned to eliminate micro-stuttering during live TV playback
|
// Tuned to eliminate micro-stuttering during live TV playback
|
||||||
@@ -200,16 +208,16 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen>
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Prevent stalls (readahead already set above)
|
// 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)
|
(_player.platform as dynamic)
|
||||||
?.setProperty('hr-seek', 'yes'); // High-res seeking
|
?.setProperty('vd-lavc-dr', 'yes'); // Direct rendering
|
||||||
(_player.platform as dynamic)
|
(_player.platform as dynamic)
|
||||||
?.setProperty('hr-seek-framedrop', 'yes'); // Drop frames to catch up
|
?.setProperty('vd-lavc-fast', 'yes'); // Fast decoding
|
||||||
|
(_player.platform as dynamic)
|
||||||
// Frame dropping policy - prefer dropping frames over stuttering
|
?.setProperty('vd-lavc-threads', '4'); // Multithreading
|
||||||
(_player.platform as dynamic)?.setProperty(
|
(_player.platform as dynamic)?.setProperty(
|
||||||
'framedrop',
|
'vd-lavc-skiploopfilter', 'all'); // Skip loop filter for performance
|
||||||
'decoder+vo',
|
|
||||||
); // Allow frame drops at decoder and video output
|
|
||||||
|
|
||||||
// ============ AUDIO CODEC SUPPORT FOR VOD ============
|
// ============ AUDIO CODEC SUPPORT FOR VOD ============
|
||||||
// V3: Explicit LAVC Downmix & Audiotrack
|
// V3: Explicit LAVC Downmix & Audiotrack
|
||||||
@@ -831,21 +839,31 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Up Arrow - Previous channel (Live only)
|
// 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) {
|
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)
|
// 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) {
|
if (widget.streamType == StreamType.live && widget.channels != null) {
|
||||||
_playNext();
|
if (key == LogicalKeyboardKey.channelDown || !_showControls) {
|
||||||
} else if (widget.streamType != StreamType.live) {
|
_playNext();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (widget.streamType != StreamType.live &&
|
||||||
|
key == LogicalKeyboardKey.arrowDown) {
|
||||||
_cycleAudioTrack();
|
_cycleAudioTrack();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return false; // Let focus handle navigation if controls shown
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cycle Aspect Ratio - secret key 'A' or digit 1
|
// 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,
|
void _playChannel(BuildContext context, Channel channel,
|
||||||
List<Channel> channels, PlaylistConfig playlist, int index) async {
|
List<Channel> channels, PlaylistConfig playlist, int index) async {
|
||||||
// Unified Player Strategy: Use LitePlayer (ExoPlayer) for Live TV (Stability)
|
final settings = ref.read(mobileSettingsProvider);
|
||||||
await Navigator.push(
|
final useNative = settings.playerEngine == 'ultra';
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
if (useNative) {
|
||||||
builder: (context) => LitePlayerScreen(
|
await Navigator.push(
|
||||||
streamId: channel.streamId,
|
context,
|
||||||
title: channel.name,
|
MaterialPageRoute(
|
||||||
playlist: playlist,
|
builder: (context) => NativePlayerScreen(
|
||||||
streamType: StreamType.live,
|
streamId: channel.streamId,
|
||||||
channels: channels, // Pass full channel list for zapping
|
title: channel.name,
|
||||||
initialIndex: index,
|
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
|
// When returning from player, set flag to prevent PopScope from going back to categories
|
||||||
if (mounted) {
|
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(
|
_buildSettingItem(
|
||||||
icon: Icons.speed,
|
icon: Icons.speed,
|
||||||
title: 'Buffer (Cache)',
|
title: 'Buffer (Cache)',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class MobileSettings {
|
|||||||
final String decoderMode; // 'auto', 'mediacodec' (HW), 'no' (SW)
|
final String decoderMode; // 'auto', 'mediacodec' (HW), 'no' (SW)
|
||||||
final String playerEngine; // 'ultra' (MPV), 'lite' (ExoPlayer)
|
final String playerEngine; // 'ultra' (MPV), 'lite' (ExoPlayer)
|
||||||
final String aspectRatioMode; // 'contain', 'cover', 'fill'
|
final String aspectRatioMode; // 'contain', 'cover', 'fill'
|
||||||
|
final bool deinterlace;
|
||||||
final int bufferDuration; // seconds, 0 = auto
|
final int bufferDuration; // seconds, 0 = auto
|
||||||
|
|
||||||
const MobileSettings({
|
const MobileSettings({
|
||||||
@@ -24,6 +25,7 @@ class MobileSettings {
|
|||||||
this.decoderMode = 'auto',
|
this.decoderMode = 'auto',
|
||||||
this.playerEngine = 'ultra',
|
this.playerEngine = 'ultra',
|
||||||
this.aspectRatioMode = 'contain',
|
this.aspectRatioMode = 'contain',
|
||||||
|
this.deinterlace = false,
|
||||||
this.bufferDuration = 0,
|
this.bufferDuration = 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ class MobileSettings {
|
|||||||
String? decoderMode,
|
String? decoderMode,
|
||||||
String? playerEngine,
|
String? playerEngine,
|
||||||
String? aspectRatioMode,
|
String? aspectRatioMode,
|
||||||
|
bool? deinterlace,
|
||||||
int? bufferDuration,
|
int? bufferDuration,
|
||||||
}) {
|
}) {
|
||||||
return MobileSettings(
|
return MobileSettings(
|
||||||
@@ -47,6 +50,7 @@ class MobileSettings {
|
|||||||
decoderMode: decoderMode ?? this.decoderMode,
|
decoderMode: decoderMode ?? this.decoderMode,
|
||||||
playerEngine: playerEngine ?? this.playerEngine,
|
playerEngine: playerEngine ?? this.playerEngine,
|
||||||
aspectRatioMode: aspectRatioMode ?? this.aspectRatioMode,
|
aspectRatioMode: aspectRatioMode ?? this.aspectRatioMode,
|
||||||
|
deinterlace: deinterlace ?? this.deinterlace,
|
||||||
bufferDuration: bufferDuration ?? this.bufferDuration,
|
bufferDuration: bufferDuration ?? this.bufferDuration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -108,6 +112,7 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
|
|||||||
_box?.get('playerEngine', defaultValue: 'ultra') as String?;
|
_box?.get('playerEngine', defaultValue: 'ultra') as String?;
|
||||||
final aspectRatioMode =
|
final aspectRatioMode =
|
||||||
_box?.get('aspectRatioMode', defaultValue: 'contain') as String?;
|
_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?;
|
final buffer = _box?.get('bufferDuration', defaultValue: 0) as int?;
|
||||||
|
|
||||||
state = MobileSettings(
|
state = MobileSettings(
|
||||||
@@ -119,6 +124,7 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
|
|||||||
decoderMode: decoderMode ?? 'auto',
|
decoderMode: decoderMode ?? 'auto',
|
||||||
playerEngine: playerEngine ?? 'ultra',
|
playerEngine: playerEngine ?? 'ultra',
|
||||||
aspectRatioMode: aspectRatioMode ?? 'contain',
|
aspectRatioMode: aspectRatioMode ?? 'contain',
|
||||||
|
deinterlace: deinterlace ?? false,
|
||||||
bufferDuration: buffer ?? 0,
|
bufferDuration: buffer ?? 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -163,6 +169,11 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
|
|||||||
_box?.put('aspectRatioMode', mode);
|
_box?.put('aspectRatioMode', mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toggleDeinterlace(bool value) {
|
||||||
|
state = state.copyWith(deinterlace: value);
|
||||||
|
_box?.put('deinterlace', value);
|
||||||
|
}
|
||||||
|
|
||||||
void setBufferDuration(int seconds) {
|
void setBufferDuration(int seconds) {
|
||||||
state = state.copyWith(bufferDuration: seconds);
|
state = state.copyWith(bufferDuration: seconds);
|
||||||
_box?.put('bufferDuration', seconds);
|
_box?.put('bufferDuration', seconds);
|
||||||
|
|||||||
Reference in new issue
Block a user