mirror of
https://github.com/R0m1k3/xtremobile.git
synced 2026-10-11 17:29:26 +02:00
feat: hybrid player strategy (VOD=Native, Live=Exo/Lite) with enhanced UI for Live TV
This commit is contained in:
1 parent
411c15f276
commit
214443f6d5
2 files changed
+112
-41
No files matched your search
@@ -13,7 +13,8 @@ import 'package:xtremflow/features/iptv/services/xtream_service_mobile.dart';
|
||||
import 'package:xtremflow/mobile/providers/mobile_settings_providers.dart';
|
||||
import 'package:xtremflow/core/theme/app_colors.dart';
|
||||
import 'package:xtremflow/mobile/providers/mobile_xtream_providers.dart';
|
||||
import 'package:xtremflow/mobile/features/iptv/screens/native_player_screen.dart' show StreamType;
|
||||
import 'package:xtremflow/mobile/features/iptv/screens/native_player_screen.dart'
|
||||
show StreamType;
|
||||
import 'package:xtremflow/features/iptv/models/xtream_models.dart' as xm;
|
||||
|
||||
/// Lite version of the player using standard video_player (ExoPlayer on Android)
|
||||
@@ -51,7 +52,8 @@ class LitePlayerScreen extends ConsumerStatefulWidget {
|
||||
ConsumerState<LitePlayerScreen> createState() => _LitePlayerScreenState();
|
||||
}
|
||||
|
||||
class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with WidgetsBindingObserver {
|
||||
class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen>
|
||||
with WidgetsBindingObserver {
|
||||
VideoPlayerController? _controller;
|
||||
XtreamServiceMobile? _xtreamService;
|
||||
|
||||
@@ -110,7 +112,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
|
||||
// Update EPG periodically for Live TV
|
||||
if (widget.streamType == StreamType.live) {
|
||||
_epgTimer = Timer.periodic(const Duration(minutes: 5), (_) => _updateEPG());
|
||||
_epgTimer =
|
||||
Timer.periodic(const Duration(minutes: 5), (_) => _updateEPG());
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) setState(() => _errorMessage = "Service Error: $e");
|
||||
@@ -121,7 +124,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
if (widget.streamType != StreamType.live || _xtreamService == null) return;
|
||||
|
||||
try {
|
||||
final currentChannelId = widget.channels?[_currentIndex].streamId ?? widget.streamId;
|
||||
final currentChannelId =
|
||||
widget.channels?[_currentIndex].streamId ?? widget.streamId;
|
||||
// Get EPG for current channel
|
||||
final epgData = await _xtreamService!.getShortEPG(currentChannelId);
|
||||
if (mounted) {
|
||||
@@ -144,7 +148,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
});
|
||||
|
||||
try {
|
||||
final currentStreamId = widget.channels != null && widget.channels!.isNotEmpty
|
||||
final currentStreamId =
|
||||
widget.channels != null && widget.channels!.isNotEmpty
|
||||
? widget.channels![_currentIndex].streamId
|
||||
: widget.streamId;
|
||||
|
||||
@@ -157,9 +162,11 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
if (widget.streamType == StreamType.live) {
|
||||
streamUrl = _xtreamService!.getLiveStreamUrl(currentStreamId);
|
||||
} else if (widget.streamType == StreamType.vod) {
|
||||
streamUrl = _xtreamService!.getVodStreamUrl(currentStreamId, widget.containerExtension ?? 'mp4');
|
||||
streamUrl = _xtreamService!.getVodStreamUrl(
|
||||
currentStreamId, widget.containerExtension ?? 'mp4');
|
||||
} else {
|
||||
streamUrl = _xtreamService!.getSeriesStreamUrl(currentStreamId, widget.containerExtension ?? 'mp4');
|
||||
streamUrl = _xtreamService!.getSeriesStreamUrl(
|
||||
currentStreamId, widget.containerExtension ?? 'mp4');
|
||||
}
|
||||
|
||||
final controller = VideoPlayerController.networkUrl(
|
||||
@@ -185,7 +192,6 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
|
||||
// Listen for errors and completion
|
||||
controller.addListener(_videoListener);
|
||||
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
@@ -252,7 +258,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
|
||||
void _playPrevious() {
|
||||
if (widget.channels == null || widget.channels!.isEmpty) return;
|
||||
final prevIndex = (_currentIndex - 1 + widget.channels!.length) % widget.channels!.length;
|
||||
final prevIndex =
|
||||
(_currentIndex - 1 + widget.channels!.length) % widget.channels!.length;
|
||||
_switchChannel(prevIndex);
|
||||
}
|
||||
|
||||
@@ -265,8 +272,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
if (_controller == null || !_controller!.value.isInitialized) return;
|
||||
final newPos = _controller!.value.position + offset;
|
||||
final clamped = Duration(
|
||||
milliseconds: newPos.inMilliseconds.clamp(0, _controller!.value.duration.inMilliseconds)
|
||||
);
|
||||
milliseconds: newPos.inMilliseconds
|
||||
.clamp(0, _controller!.value.duration.inMilliseconds));
|
||||
await _controller!.seekTo(clamped);
|
||||
_onUserInteraction();
|
||||
}
|
||||
@@ -276,12 +283,16 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
if (event is! KeyDownEvent) return false;
|
||||
final key = event.logicalKey;
|
||||
|
||||
if (key == LogicalKeyboardKey.mediaPlay || key == LogicalKeyboardKey.mediaPause || key == LogicalKeyboardKey.mediaPlayPause) {
|
||||
if (key == LogicalKeyboardKey.mediaPlay ||
|
||||
key == LogicalKeyboardKey.mediaPause ||
|
||||
key == LogicalKeyboardKey.mediaPlayPause) {
|
||||
_togglePlayPause();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == LogicalKeyboardKey.select || key == LogicalKeyboardKey.enter || key == LogicalKeyboardKey.space) {
|
||||
if (key == LogicalKeyboardKey.select ||
|
||||
key == LogicalKeyboardKey.enter ||
|
||||
key == LogicalKeyboardKey.space) {
|
||||
if (!_showControls) {
|
||||
_onUserInteraction();
|
||||
return true;
|
||||
@@ -289,7 +300,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key == LogicalKeyboardKey.arrowDown || key == LogicalKeyboardKey.channelDown) {
|
||||
if (key == LogicalKeyboardKey.arrowDown ||
|
||||
key == LogicalKeyboardKey.channelDown) {
|
||||
if (widget.streamType == StreamType.live) {
|
||||
_playPrevious();
|
||||
_onUserInteraction();
|
||||
@@ -297,7 +309,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == LogicalKeyboardKey.arrowUp || key == LogicalKeyboardKey.channelUp) {
|
||||
if (key == LogicalKeyboardKey.arrowUp ||
|
||||
key == LogicalKeyboardKey.channelUp) {
|
||||
if (widget.streamType == StreamType.live) {
|
||||
_playNext();
|
||||
_onUserInteraction();
|
||||
@@ -330,14 +343,16 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
|
||||
void _startClock() {
|
||||
_updateTime();
|
||||
_clockTimer = Timer.periodic(const Duration(seconds: 1), (_) => _updateTime());
|
||||
_clockTimer =
|
||||
Timer.periodic(const Duration(seconds: 1), (_) => _updateTime());
|
||||
}
|
||||
|
||||
void _updateTime() {
|
||||
if (mounted) {
|
||||
final now = DateTime.now();
|
||||
setState(() {
|
||||
_currentTime = "${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}";
|
||||
_currentTime =
|
||||
"${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}";
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -396,10 +411,11 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
),
|
||||
|
||||
if (_errorMessage != null)
|
||||
Center(child: Text(_errorMessage!, style: const TextStyle(color: Colors.red))),
|
||||
Center(
|
||||
child: Text(_errorMessage!,
|
||||
style: const TextStyle(color: Colors.red))),
|
||||
|
||||
if (_showControls)
|
||||
_buildControls(title),
|
||||
if (_showControls) _buildControls(title),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -411,7 +427,9 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
children: [
|
||||
// Top Bar
|
||||
Positioned(
|
||||
top: 0, left: 0, right: 0,
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
color: Colors.black54,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||
@@ -423,7 +441,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
child: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
if (widget.channels != null && widget.channels![_currentIndex].streamIcon.isNotEmpty)
|
||||
if (widget.channels != null &&
|
||||
widget.channels![_currentIndex].streamIcon.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: SizedBox(
|
||||
@@ -435,28 +454,45 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(title, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
Text(title,
|
||||
style: const TextStyle(
|
||||
color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
const Spacer(),
|
||||
// NO RATIO TOGGLE HERE
|
||||
const SizedBox(width: 16),
|
||||
Text(_currentTime, style: const TextStyle(color: Colors.white70)),
|
||||
Text(_currentTime,
|
||||
style: const TextStyle(color: Colors.white70)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Center Controls
|
||||
// Bottom Controls (Aligned with EPG)
|
||||
Positioned(
|
||||
bottom: 100,
|
||||
bottom: 80,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Live TV: Prev Channel
|
||||
if (widget.streamType == StreamType.live &&
|
||||
widget.channels != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 24),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.skip_previous,
|
||||
color: Colors.white, size: 48),
|
||||
onPressed: _playPrevious,
|
||||
),
|
||||
),
|
||||
|
||||
// VOD: Replay 10s
|
||||
if (widget.streamType != StreamType.live) ...[
|
||||
IconButton(
|
||||
icon: const Icon(Icons.replay_10, color: Colors.white70, size: 36),
|
||||
icon: const Icon(Icons.replay_10,
|
||||
color: Colors.white70, size: 36),
|
||||
onPressed: () => _seek(const Duration(seconds: -10)),
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
@@ -476,27 +512,45 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
_isPlaying ? Icons.pause_rounded : Icons.play_arrow_rounded,
|
||||
_isPlaying
|
||||
? Icons.pause_rounded
|
||||
: Icons.play_arrow_rounded,
|
||||
color: Colors.white,
|
||||
size: 48,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// VOD: Forward 10s
|
||||
if (widget.streamType != StreamType.live) ...[
|
||||
const SizedBox(width: 24),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.forward_10, color: Colors.white70, size: 36),
|
||||
icon: const Icon(Icons.forward_10,
|
||||
color: Colors.white70, size: 36),
|
||||
onPressed: () => _seek(const Duration(seconds: 10)),
|
||||
),
|
||||
],
|
||||
|
||||
// Live TV: Next Channel
|
||||
if (widget.streamType == StreamType.live &&
|
||||
widget.channels != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 24),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.skip_next,
|
||||
color: Colors.white, size: 48),
|
||||
onPressed: _playNext,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// EPG Content
|
||||
if (widget.streamType == StreamType.live && _epg != null && _epg!.nowPlaying != null)
|
||||
if (widget.streamType == StreamType.live &&
|
||||
_epg != null &&
|
||||
_epg!.nowPlaying != null)
|
||||
Positioned(
|
||||
bottom: 80,
|
||||
left: 24,
|
||||
@@ -517,7 +571,10 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
children: [
|
||||
Text(
|
||||
_epg!.nowPlaying!,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -526,7 +583,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
"A suivre: ${_epg!.nextPlaying}",
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
||||
style: const TextStyle(
|
||||
color: Colors.white70, fontSize: 14),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -535,13 +593,18 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
margin: const EdgeInsets.only(left: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text('LIVE', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12)),
|
||||
child: const Text('LIVE',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -551,18 +614,25 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
// Progress Bar (VOD)
|
||||
if (widget.streamType != StreamType.live)
|
||||
Positioned(
|
||||
bottom: 0, left: 0, right: 0,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
color: Colors.black54,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(_formatDuration(_position), style: const TextStyle(color: Colors.white)),
|
||||
Text(_formatDuration(_position),
|
||||
style: const TextStyle(color: Colors.white)),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: _position.inSeconds.toDouble().clamp(0, _duration.inSeconds.toDouble()),
|
||||
value: _position.inSeconds
|
||||
.toDouble()
|
||||
.clamp(0, _duration.inSeconds.toDouble()),
|
||||
min: 0,
|
||||
max: _duration.inSeconds.toDouble() > 0 ? _duration.inSeconds.toDouble() : 1.0,
|
||||
max: _duration.inSeconds.toDouble() > 0
|
||||
? _duration.inSeconds.toDouble()
|
||||
: 1.0,
|
||||
activeColor: AppColors.primary,
|
||||
inactiveColor: Colors.white24,
|
||||
onChanged: (val) {
|
||||
@@ -578,7 +648,8 @@ class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with Widget
|
||||
},
|
||||
),
|
||||
),
|
||||
Text(_formatDuration(_duration), style: const TextStyle(color: Colors.white)),
|
||||
Text(_formatDuration(_duration),
|
||||
style: const TextStyle(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -406,11 +406,11 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
|
||||
|
||||
void _playChannel(BuildContext context, Channel channel,
|
||||
List<Channel> channels, PlaylistConfig playlist, int index) async {
|
||||
// Unified Player Strategy: Use NativePlayer (Ultra) for everything
|
||||
// Unified Player Strategy: Use LitePlayer (ExoPlayer) for Live TV (Stability)
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => NativePlayerScreen(
|
||||
builder: (context) => LitePlayerScreen(
|
||||
streamId: channel.streamId,
|
||||
title: channel.name,
|
||||
playlist: playlist,
|
||||
|
||||
Reference in new issue
Block a user