mirror of
https://github.com/R0m1k3/xtremobile.git
synced 2026-10-24 07:38:16 +02:00
feat: introduce XtreamServiceMobile for IPTV API interactions and DnsFallbackInterceptor for network robustness.
This commit is contained in:
1 parent
332295a57a
commit
2406b9b100
16 files changed
+1693
-399
No files matched your search
@@ -9,7 +9,7 @@ class SettingsApiService {
|
|||||||
// Restore token from localStorage before making the request
|
// Restore token from localStorage before making the request
|
||||||
_api.restoreToken();
|
_api.restoreToken();
|
||||||
|
|
||||||
if (_api.getStoredToken() == null) {
|
if (_api.getToken() == null) {
|
||||||
print('[SettingsAPI] getSettings: No auth token found');
|
print('[SettingsAPI] getSettings: No auth token found');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ class SettingsApiService {
|
|||||||
// Restore token from localStorage before making the request
|
// Restore token from localStorage before making the request
|
||||||
_api.restoreToken();
|
_api.restoreToken();
|
||||||
|
|
||||||
if (_api.getStoredToken() == null) {
|
if (_api.getToken() == null) {
|
||||||
print('[SettingsAPI] saveSettings: No auth token found');
|
print('[SettingsAPI] saveSettings: No auth token found');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,17 @@ class AppColors {
|
|||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomRight,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// Apple TV Style Background Gradient (Grey/Black Radial)
|
||||||
|
static const RadialGradient appleTvGradient = RadialGradient(
|
||||||
|
center: Alignment.center,
|
||||||
|
radius: 1.5,
|
||||||
|
colors: [
|
||||||
|
Color(0xFF2C2C2E), // Apple Dark Gray
|
||||||
|
Color(0xFF000000), // Black
|
||||||
|
],
|
||||||
|
stops: [0.0, 1.0],
|
||||||
|
);
|
||||||
|
|
||||||
// ============ TEXT ============
|
// ============ TEXT ============
|
||||||
static const Color textPrimary = Color(0xFFFFFFFF);
|
static const Color textPrimary = Color(0xFFFFFFFF);
|
||||||
static const Color textSecondary = Color(0xFF9E9E9E); // Medium Grey
|
static const Color textSecondary = Color(0xFF9E9E9E); // Medium Grey
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ class Season {
|
|||||||
class Episode {
|
class Episode {
|
||||||
final String id;
|
final String id;
|
||||||
final int episodeNum;
|
final int episodeNum;
|
||||||
|
final int seasonNum; // Added field
|
||||||
final String title;
|
final String title;
|
||||||
final String? containerExtension;
|
final String? containerExtension;
|
||||||
final String? info;
|
final String? info;
|
||||||
@@ -143,6 +144,7 @@ class Episode {
|
|||||||
const Episode({
|
const Episode({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.episodeNum,
|
required this.episodeNum,
|
||||||
|
this.seasonNum = 0, // Default to 0 if unknown
|
||||||
required this.title,
|
required this.title,
|
||||||
this.containerExtension,
|
this.containerExtension,
|
||||||
this.info,
|
this.info,
|
||||||
@@ -150,10 +152,11 @@ class Episode {
|
|||||||
this.durationSecs,
|
this.durationSecs,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Episode.fromJson(Map<String, dynamic> json) {
|
factory Episode.fromJson(Map<String, dynamic> json, {int? season}) { // Accept season param
|
||||||
return Episode(
|
return Episode(
|
||||||
id: json['id']?.toString() ?? '',
|
id: json['id']?.toString() ?? '',
|
||||||
episodeNum: int.tryParse(json['episode_num']?.toString() ?? '1') ?? 1,
|
episodeNum: int.tryParse(json['episode_num']?.toString() ?? '1') ?? 1,
|
||||||
|
seasonNum: season ?? int.tryParse(json['season']?.toString() ?? '0') ?? 0,
|
||||||
title: json['title']?.toString() ?? 'Episode ${json['episode_num'] ?? 1}',
|
title: json['title']?.toString() ?? 'Episode ${json['episode_num'] ?? 1}',
|
||||||
containerExtension: json['container_extension']?.toString() ?? 'mkv',
|
containerExtension: json['container_extension']?.toString() ?? 'mkv',
|
||||||
info: json['info']?.toString(),
|
info: json['info']?.toString(),
|
||||||
@@ -161,6 +164,9 @@ class Episode {
|
|||||||
durationSecs: int.tryParse(json['duration_secs']?.toString() ?? '0'),
|
durationSecs: int.tryParse(json['duration_secs']?.toString() ?? '0'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getter for compatibility
|
||||||
|
String get streamId => id;
|
||||||
|
|
||||||
String getStreamUrl(String dns, String username, String password) {
|
String getStreamUrl(String dns, String username, String password) {
|
||||||
return '$dns/series/$username/$password/$id.${containerExtension ?? 'mkv'}';
|
return '$dns/series/$username/$password/$id.${containerExtension ?? 'mkv'}';
|
||||||
@@ -205,7 +211,7 @@ class SeriesInfo {
|
|||||||
episodesData.forEach((seasonNum, episodesList) {
|
episodesData.forEach((seasonNum, episodesList) {
|
||||||
final seasonInt = int.tryParse(seasonNum) ?? 1;
|
final seasonInt = int.tryParse(seasonNum) ?? 1;
|
||||||
final episodeList = (episodesList as List<dynamic>?)
|
final episodeList = (episodesList as List<dynamic>?)
|
||||||
?.map((e) => Episode.fromJson(e as Map<String, dynamic>))
|
?.map((e) => Episode.fromJson(e as Map<String, dynamic>, season: seasonInt))
|
||||||
.toList() ?? [];
|
.toList() ?? [];
|
||||||
episodes[seasonInt] = episodeList;
|
episodes[seasonInt] = episodeList;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,586 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:video_player/video_player.dart';
|
||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
import 'package:xtremflow/mobile/widgets/tv_focusable.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:xtremflow/core/models/iptv_models.dart';
|
||||||
|
import 'package:xtremflow/core/models/playlist_config.dart';
|
||||||
|
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/features/iptv/models/xtream_models.dart' as xm;
|
||||||
|
|
||||||
|
/// Lite version of the player using standard video_player (ExoPlayer on Android)
|
||||||
|
/// Targeted for 1GB RAM devices where MPV is too heavy.
|
||||||
|
class LitePlayerScreen extends ConsumerStatefulWidget {
|
||||||
|
final String streamId;
|
||||||
|
final String title;
|
||||||
|
final StreamType streamType;
|
||||||
|
final String? containerExtension;
|
||||||
|
final PlaylistConfig playlist;
|
||||||
|
final List<Channel>? channels;
|
||||||
|
final int initialIndex;
|
||||||
|
|
||||||
|
// For series episodes
|
||||||
|
final dynamic seriesId;
|
||||||
|
final int? season;
|
||||||
|
final int? episodeNum;
|
||||||
|
|
||||||
|
const LitePlayerScreen({
|
||||||
|
super.key,
|
||||||
|
required this.streamId,
|
||||||
|
required this.title,
|
||||||
|
required this.playlist,
|
||||||
|
required this.streamType,
|
||||||
|
this.containerExtension,
|
||||||
|
this.channels,
|
||||||
|
this.initialIndex = 0,
|
||||||
|
this.seriesId,
|
||||||
|
this.season,
|
||||||
|
this.episodeNum,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<LitePlayerScreen> createState() => _LitePlayerScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LitePlayerScreenState extends ConsumerState<LitePlayerScreen> with WidgetsBindingObserver {
|
||||||
|
VideoPlayerController? _controller;
|
||||||
|
XtreamServiceMobile? _xtreamService;
|
||||||
|
|
||||||
|
bool _isLoading = true;
|
||||||
|
String? _errorMessage;
|
||||||
|
late int _currentIndex;
|
||||||
|
bool _showControls = true;
|
||||||
|
bool _isPlaying = false;
|
||||||
|
|
||||||
|
// EPG
|
||||||
|
xm.ShortEPG? _epg;
|
||||||
|
Timer? _epgTimer;
|
||||||
|
|
||||||
|
// Progress & Seeking
|
||||||
|
Duration _position = Duration.zero;
|
||||||
|
Duration _duration = Duration.zero;
|
||||||
|
bool _isSeeking = false;
|
||||||
|
|
||||||
|
// Focus Nodes
|
||||||
|
final FocusNode _playPauseFocusNode = FocusNode();
|
||||||
|
final FocusNode _backFocusNode = FocusNode();
|
||||||
|
|
||||||
|
Timer? _controlsTimer;
|
||||||
|
Timer? _clockTimer;
|
||||||
|
String _currentTime = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
HardwareKeyboard.instance.addHandler(_handleKeyEvent);
|
||||||
|
|
||||||
|
_currentIndex = widget.initialIndex;
|
||||||
|
_startClock();
|
||||||
|
|
||||||
|
// Lock orientation
|
||||||
|
SystemChrome.setPreferredOrientations([
|
||||||
|
DeviceOrientation.landscapeLeft,
|
||||||
|
DeviceOrientation.landscapeRight,
|
||||||
|
]);
|
||||||
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||||
|
|
||||||
|
_initializeService();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _initializeService() async {
|
||||||
|
try {
|
||||||
|
final dir = await getApplicationDocumentsDirectory();
|
||||||
|
_xtreamService = XtreamServiceMobile(dir.path);
|
||||||
|
await _xtreamService!.setPlaylistAsync(widget.playlist);
|
||||||
|
_loadStream();
|
||||||
|
_updateEPG(); // Initial Load
|
||||||
|
|
||||||
|
// Update EPG periodically for Live TV
|
||||||
|
if (widget.streamType == StreamType.live) {
|
||||||
|
_epgTimer = Timer.periodic(const Duration(minutes: 5), (_) => _updateEPG());
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) setState(() => _errorMessage = "Service Error: $e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _updateEPG() async {
|
||||||
|
if (widget.streamType != StreamType.live || _xtreamService == null) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final currentChannelId = widget.channels?[_currentIndex].streamId ?? widget.streamId;
|
||||||
|
// Get EPG for current channel
|
||||||
|
final epgData = await _xtreamService!.getShortEPG(currentChannelId);
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => _epg = epgData);
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadStream() async {
|
||||||
|
if (_xtreamService == null) return;
|
||||||
|
|
||||||
|
// cleanup previous
|
||||||
|
await _controller?.dispose();
|
||||||
|
_controller = null;
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
_errorMessage = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
final currentStreamId = widget.channels != null && widget.channels!.isNotEmpty
|
||||||
|
? widget.channels![_currentIndex].streamId
|
||||||
|
: widget.streamId;
|
||||||
|
|
||||||
|
// Update EPG when changing channels
|
||||||
|
if (widget.streamType == StreamType.live) {
|
||||||
|
_updateEPG();
|
||||||
|
}
|
||||||
|
|
||||||
|
String streamUrl;
|
||||||
|
if (widget.streamType == StreamType.live) {
|
||||||
|
streamUrl = _xtreamService!.getLiveStreamUrl(currentStreamId);
|
||||||
|
} else if (widget.streamType == StreamType.vod) {
|
||||||
|
streamUrl = _xtreamService!.getVodStreamUrl(currentStreamId, widget.containerExtension ?? 'mp4');
|
||||||
|
} else {
|
||||||
|
streamUrl = _xtreamService!.getSeriesStreamUrl(currentStreamId, widget.containerExtension ?? 'mp4');
|
||||||
|
}
|
||||||
|
|
||||||
|
final controller = VideoPlayerController.networkUrl(
|
||||||
|
Uri.parse(streamUrl),
|
||||||
|
httpHeaders: {'User-Agent': 'XtremFlow/1.0'},
|
||||||
|
);
|
||||||
|
|
||||||
|
_controller = controller;
|
||||||
|
await controller.initialize();
|
||||||
|
|
||||||
|
if (!mounted) {
|
||||||
|
await controller.dispose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await controller.play();
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
_isPlaying = true;
|
||||||
|
_duration = controller.value.duration;
|
||||||
|
});
|
||||||
|
_resetControlsTimer();
|
||||||
|
|
||||||
|
// Listen for errors and completion via controller listener
|
||||||
|
controller.addListener(_videoListener);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
_errorMessage = "Playback Error: $e";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _videoListener() {
|
||||||
|
if (_controller == null || !mounted) return;
|
||||||
|
|
||||||
|
// Update Play/Pause state
|
||||||
|
final isPlaying = _controller!.value.isPlaying;
|
||||||
|
if (isPlaying != _isPlaying) {
|
||||||
|
setState(() => _isPlaying = isPlaying);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Duration/Position (if not seeking)
|
||||||
|
if (!_isSeeking) {
|
||||||
|
final pos = _controller!.value.position;
|
||||||
|
final dur = _controller!.value.duration;
|
||||||
|
if (pos != _position || dur != _duration) {
|
||||||
|
setState(() {
|
||||||
|
_position = pos;
|
||||||
|
_duration = dur;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_controller!.value.hasError) {
|
||||||
|
setState(() => _errorMessage = _controller!.value.errorDescription);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onUserInteraction() {
|
||||||
|
setState(() => _showControls = true);
|
||||||
|
_resetControlsTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _resetControlsTimer() {
|
||||||
|
_controlsTimer?.cancel();
|
||||||
|
if (_showControls && _isPlaying) {
|
||||||
|
_controlsTimer = Timer(const Duration(seconds: 5), () {
|
||||||
|
if (mounted) setState(() => _showControls = false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _togglePlayPause() {
|
||||||
|
if (_controller == null) return;
|
||||||
|
if (_controller!.value.isPlaying) {
|
||||||
|
_controller!.pause();
|
||||||
|
} else {
|
||||||
|
_controller!.play();
|
||||||
|
}
|
||||||
|
_onUserInteraction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _playNext() {
|
||||||
|
if (widget.channels == null || widget.channels!.isEmpty) return;
|
||||||
|
final nextIndex = (_currentIndex + 1) % widget.channels!.length;
|
||||||
|
_switchChannel(nextIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _playPrevious() {
|
||||||
|
if (widget.channels == null || widget.channels!.isEmpty) return;
|
||||||
|
final prevIndex = (_currentIndex - 1 + widget.channels!.length) % widget.channels!.length;
|
||||||
|
_switchChannel(prevIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _switchChannel(int index) {
|
||||||
|
setState(() => _currentIndex = index);
|
||||||
|
_loadStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _seek(Duration offset) async {
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
await _controller!.seekTo(clamped);
|
||||||
|
_onUserInteraction();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simplified Key Handler
|
||||||
|
bool _handleKeyEvent(KeyEvent event) {
|
||||||
|
if (event is! KeyDownEvent) return false;
|
||||||
|
final key = event.logicalKey;
|
||||||
|
|
||||||
|
// Media Keys (Remote)
|
||||||
|
if (key == LogicalKeyboardKey.mediaPlay || key == LogicalKeyboardKey.mediaPause || key == LogicalKeyboardKey.mediaPlayPause) {
|
||||||
|
_togglePlayPause();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == LogicalKeyboardKey.select || key == LogicalKeyboardKey.enter || key == LogicalKeyboardKey.space) {
|
||||||
|
if (!_showControls) {
|
||||||
|
_onUserInteraction();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// If controls visible, let focus system handle it
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seek / Channel Change
|
||||||
|
|
||||||
|
if (key == LogicalKeyboardKey.arrowDown || key == LogicalKeyboardKey.channelDown) {
|
||||||
|
// User requested "Down" => Previous Channel (Index - 1)
|
||||||
|
if (widget.streamType == StreamType.live) {
|
||||||
|
_playPrevious();
|
||||||
|
_onUserInteraction(); // Show OSD
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == LogicalKeyboardKey.arrowUp || key == LogicalKeyboardKey.channelUp) {
|
||||||
|
// User requested "Up" => Next Channel (Index + 1)
|
||||||
|
if (widget.streamType == StreamType.live) {
|
||||||
|
_playNext();
|
||||||
|
_onUserInteraction(); // Show OSD
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (widget.streamType != StreamType.live) {
|
||||||
|
if (key == LogicalKeyboardKey.arrowLeft) {
|
||||||
|
_seek(const Duration(seconds: -10));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (key == LogicalKeyboardKey.arrowRight) {
|
||||||
|
_seek(const Duration(seconds: 10));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == LogicalKeyboardKey.escape || key == LogicalKeyboardKey.goBack) {
|
||||||
|
if (_showControls) {
|
||||||
|
setState(() => _showControls = false);
|
||||||
|
} else {
|
||||||
|
// Force pop completely to return to list, not just playlist selection
|
||||||
|
// Check navigator stack if needed, but standard pop should work if pushed correctly
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _startClock() {
|
||||||
|
_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')}";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
|
HardwareKeyboard.instance.removeHandler(_handleKeyEvent);
|
||||||
|
_controlsTimer?.cancel();
|
||||||
|
_clockTimer?.cancel();
|
||||||
|
_epgTimer?.cancel();
|
||||||
|
_controller?.dispose();
|
||||||
|
_xtreamService?.dispose();
|
||||||
|
_playPauseFocusNode.dispose();
|
||||||
|
_backFocusNode.dispose();
|
||||||
|
|
||||||
|
SystemChrome.setPreferredOrientations([
|
||||||
|
DeviceOrientation.portraitUp,
|
||||||
|
DeviceOrientation.landscapeLeft,
|
||||||
|
DeviceOrientation.landscapeRight,
|
||||||
|
]);
|
||||||
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
String _formatDuration(Duration duration) {
|
||||||
|
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
||||||
|
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
|
||||||
|
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
|
||||||
|
return "${twoDigits(duration.inHours)}:$twoDigitMinutes:$twoDigitSeconds";
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final title = widget.channels != null && widget.channels!.isNotEmpty
|
||||||
|
? widget.channels![_currentIndex].name
|
||||||
|
: widget.title;
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
body: GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: _onUserInteraction,
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: _controller != null && _controller!.value.isInitialized
|
||||||
|
? AspectRatio(
|
||||||
|
aspectRatio: _controller!.value.aspectRatio,
|
||||||
|
child: VideoPlayer(_controller!),
|
||||||
|
)
|
||||||
|
: const CircularProgressIndicator(color: AppColors.primary),
|
||||||
|
),
|
||||||
|
|
||||||
|
if (_errorMessage != null)
|
||||||
|
Center(child: Text(_errorMessage!, style: const TextStyle(color: Colors.red))),
|
||||||
|
|
||||||
|
if (_showControls)
|
||||||
|
_buildControls(title),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildControls(String title) {
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
// Top Bar
|
||||||
|
Positioned(
|
||||||
|
top: 0, left: 0, right: 0,
|
||||||
|
child: Container(
|
||||||
|
color: Colors.black54,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
TVFocusable(
|
||||||
|
focusNode: _backFocusNode,
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Icon(Icons.arrow_back, color: Colors.white),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
// Icon
|
||||||
|
if (widget.channels != null && widget.channels![_currentIndex].streamIcon.isNotEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 12),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
child: CachedNetworkImage(
|
||||||
|
imageUrl: widget.channels![_currentIndex].streamIcon,
|
||||||
|
errorWidget: (_,__,___) => const SizedBox.shrink(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text('LITE PLAYER: $title', style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||||
|
const Spacer(),
|
||||||
|
Text(_currentTime, style: const TextStyle(color: Colors.white70)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Center Controls
|
||||||
|
Center(
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
if (widget.streamType == StreamType.live) ...[
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.keyboard_arrow_up, color: Colors.white, size: 40),
|
||||||
|
onPressed: _playPrevious,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 32),
|
||||||
|
] else ...[
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.replay_10, color: Colors.white, size: 40),
|
||||||
|
onPressed: () => _seek(const Duration(seconds: -10)),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 32),
|
||||||
|
],
|
||||||
|
|
||||||
|
TVFocusable(
|
||||||
|
focusNode: _playPauseFocusNode,
|
||||||
|
onPressed: _togglePlayPause,
|
||||||
|
child: Icon(
|
||||||
|
_isPlaying ? Icons.pause_circle_filled : Icons.play_circle_filled,
|
||||||
|
color: AppColors.primary,
|
||||||
|
size: 64,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
if (widget.streamType == StreamType.live) ...[
|
||||||
|
const SizedBox(width: 32),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.keyboard_arrow_down, color: Colors.white, size: 40),
|
||||||
|
onPressed: _playNext,
|
||||||
|
),
|
||||||
|
] else ...[
|
||||||
|
const SizedBox(width: 32),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.forward_10, color: Colors.white, size: 40),
|
||||||
|
onPressed: () => _seek(const Duration(seconds: 10)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// EPG Content (Bottom Left)
|
||||||
|
if (widget.streamType == StreamType.live && _epg != null && _epg!.nowPlaying != null)
|
||||||
|
Positioned(
|
||||||
|
bottom: 80, // Above progress/bottom bar
|
||||||
|
left: 24,
|
||||||
|
width: 350,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black.withOpacity(0.7),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: Colors.white24),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
_epg!.nowPlaying!,
|
||||||
|
style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
if (_epg!.nextPlaying != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 4),
|
||||||
|
child: Text(
|
||||||
|
"A suivre: ${_epg!.nextPlaying}",
|
||||||
|
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// LIVE Badge
|
||||||
|
Container(
|
||||||
|
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)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Progress Bar (Bottom) - Only for VOD
|
||||||
|
if (widget.streamType != StreamType.live)
|
||||||
|
Positioned(
|
||||||
|
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)),
|
||||||
|
Expanded(
|
||||||
|
child: Slider(
|
||||||
|
value: _position.inSeconds.toDouble().clamp(0, _duration.inSeconds.toDouble()),
|
||||||
|
min: 0,
|
||||||
|
max: _duration.inSeconds.toDouble(),
|
||||||
|
activeColor: AppColors.primary,
|
||||||
|
inactiveColor: Colors.white24,
|
||||||
|
onChanged: (val) {
|
||||||
|
setState(() {
|
||||||
|
_position = Duration(seconds: val.toInt());
|
||||||
|
_isSeeking = true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onChangeEnd: (val) {
|
||||||
|
_controller?.seekTo(Duration(seconds: val.toInt()));
|
||||||
|
_isSeeking = false;
|
||||||
|
_onUserInteraction();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(_formatDuration(_duration), style: const TextStyle(color: Colors.white)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,77 +13,130 @@ final playlistsProvider = FutureProvider<List<PlaylistConfig>>((ref) async {
|
|||||||
return service.getPlaylists();
|
return service.getPlaylists();
|
||||||
});
|
});
|
||||||
|
|
||||||
class MobilePlaylistSelectionScreen extends ConsumerWidget {
|
class MobilePlaylistSelectionScreen extends ConsumerStatefulWidget {
|
||||||
const MobilePlaylistSelectionScreen({super.key});
|
final bool manageMode;
|
||||||
|
const MobilePlaylistSelectionScreen({super.key, this.manageMode = false});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
ConsumerState<MobilePlaylistSelectionScreen> createState() => _MobilePlaylistSelectionScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MobilePlaylistSelectionScreenState extends ConsumerState<MobilePlaylistSelectionScreen> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (!widget.manageMode) {
|
||||||
|
// Check for auto-login after build
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
_checkAutoLogin();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _checkAutoLogin() async {
|
||||||
|
final playlists = await ref.read(playlistsProvider.future);
|
||||||
|
if (playlists.isNotEmpty && mounted) {
|
||||||
|
// Auto-login to the first playlist (or last used)
|
||||||
|
// Ideally last used, but for now first is fine as per request "une playlist existe".
|
||||||
|
context.go('/dashboard', extra: playlists.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
final currentUser = ref.watch(authProvider).currentUser;
|
final currentUser = ref.watch(authProvider).currentUser;
|
||||||
final playlistsAsync = ref.watch(playlistsProvider);
|
final playlistsAsync = ref.watch(playlistsProvider);
|
||||||
|
|
||||||
return Theme(
|
return Theme(
|
||||||
data: MobileTheme.darkTheme,
|
data: MobileTheme.darkTheme,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
|
extendBodyBehindAppBar: true, // For gradient
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Playlists'),
|
title: Text(widget.manageMode ? 'Gérer les Playlists' : 'Playlists'),
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
elevation: 0,
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
if (widget.manageMode)
|
||||||
icon: const Icon(Icons.logout),
|
IconButton(
|
||||||
onPressed: () async {
|
icon: const Icon(Icons.close),
|
||||||
await ref.read(authProvider.notifier).logout();
|
onPressed: () => Navigator.pop(context),
|
||||||
if (context.mounted) {
|
),
|
||||||
context.go('/login');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: playlistsAsync.when(
|
body: Container(
|
||||||
loading: () => const Center(child: CircularProgressIndicator()),
|
decoration: const BoxDecoration(
|
||||||
error: (error, stack) => Center(
|
gradient: AppColors.appleTvGradient,
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.error_outline, size: 48, color: AppColors.error),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Text('Error loading playlists', style: GoogleFonts.inter()),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => ref.refresh(playlistsProvider),
|
|
||||||
child: const Text('Retry'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
data: (playlists) {
|
child: playlistsAsync.when(
|
||||||
if (playlists.isEmpty) {
|
loading: () => const Center(child: CircularProgressIndicator()),
|
||||||
return Center(
|
error: (error, stack) => Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.playlist_remove, size: 48, color: AppColors.textSecondary),
|
const Icon(Icons.error_outline, size: 48, color: AppColors.error),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text('No playlists available', style: GoogleFonts.inter(color: AppColors.textSecondary)),
|
Text('Erreur de chargement', style: GoogleFonts.inter(color: Colors.white)),
|
||||||
],
|
TextButton(
|
||||||
),
|
onPressed: () => ref.refresh(playlistsProvider),
|
||||||
);
|
child: const Text('Réessayer'),
|
||||||
}
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
data: (playlists) {
|
||||||
|
if (playlists.isEmpty) {
|
||||||
|
// Even in auto-mode, if empty we show this (or add button)
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.playlist_add, size: 64, color: Colors.white54),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
Text(
|
||||||
|
'Aucune playlist configurée',
|
||||||
|
style: GoogleFonts.inter(fontSize: 18, color: Colors.white70),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
ElevatedButton.icon(
|
||||||
|
onPressed: () {
|
||||||
|
// Logic to add playlist (usually dialog or separate screen)
|
||||||
|
// specific logic for add playlist
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
label: const Text('Ajouter une Playlist'),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: AppColors.primary,
|
||||||
|
foregroundColor: Colors.black,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return ListView.separated(
|
return ListView.separated(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.fromLTRB(16, 100, 16, 16), // Top padding for AppBar
|
||||||
itemCount: playlists.length,
|
itemCount: playlists.length,
|
||||||
separatorBuilder: (context, index) => const SizedBox(height: 16),
|
separatorBuilder: (context, index) => const SizedBox(height: 16),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final playlist = playlists[index];
|
final playlist = playlists[index];
|
||||||
return _MobilePlaylistCard(
|
return _MobilePlaylistCard(
|
||||||
playlist: playlist,
|
playlist: playlist,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Mobile navigation to dashboard with playlist
|
if (widget.manageMode) {
|
||||||
context.go('/dashboard', extra: playlist);
|
// In manage mode, maybe we want to edit or delete?
|
||||||
},
|
// For now, just switch to it.
|
||||||
);
|
context.go('/dashboard', extra: playlist);
|
||||||
},
|
} else {
|
||||||
);
|
context.go('/dashboard', extra: playlist);
|
||||||
},
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:cached_network_image/cached_network_image.dart';
|
|||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import '../../../../core/models/playlist_config.dart';
|
import '../../../../core/models/playlist_config.dart';
|
||||||
import '../../../../features/iptv/models/xtream_models.dart';
|
import '../../../../features/iptv/models/xtream_models.dart';
|
||||||
|
import 'package:xtremflow/mobile/features/iptv/screens/lite_player_screen.dart';
|
||||||
import '../../../providers/mobile_xtream_providers.dart';
|
import '../../../providers/mobile_xtream_providers.dart';
|
||||||
import '../../../providers/mobile_settings_providers.dart';
|
import '../../../providers/mobile_settings_providers.dart';
|
||||||
import 'native_player_screen.dart';
|
import 'native_player_screen.dart';
|
||||||
@@ -104,7 +105,7 @@ class _MobileSeriesDetailScreenState extends ConsumerState<MobileSeriesDetailScr
|
|||||||
slivers: [
|
slivers: [
|
||||||
// App Bar with Cover
|
// App Bar with Cover
|
||||||
SliverAppBar(
|
SliverAppBar(
|
||||||
expandedHeight: 400,
|
expandedHeight: 280, // Reduced from 400 for better TV visibility
|
||||||
pinned: true,
|
pinned: true,
|
||||||
backgroundColor: AppColors.background,
|
backgroundColor: AppColors.background,
|
||||||
leading: Container(
|
leading: Container(
|
||||||
@@ -280,21 +281,41 @@ class _MobileSeriesDetailScreenState extends ConsumerState<MobileSeriesDetailScr
|
|||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Watch progress is tracked in player at 80% completion
|
// Watch progress is tracked in player at 80% completion
|
||||||
Navigator.push(
|
final engine = ref.read(mobileSettingsProvider).playerEngine;
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
if (engine == 'lite') {
|
||||||
builder: (context) => NativePlayerScreen(
|
Navigator.push(
|
||||||
streamId: episode.id,
|
context,
|
||||||
title: '${widget.series.name} - ${episode.title}',
|
MaterialPageRoute(
|
||||||
playlist: widget.playlist,
|
builder: (context) => LitePlayerScreen(
|
||||||
streamType: StreamType.series,
|
streamId: episode.streamId,
|
||||||
containerExtension: episode.containerExtension ?? 'mkv',
|
title: "${widget.series.name} S${episode.seasonNum}E${episode.episodeNum}",
|
||||||
seriesId: widget.series.seriesId,
|
playlist: widget.playlist,
|
||||||
season: _selectedSeason,
|
streamType: StreamType.series,
|
||||||
episodeNum: episode.episodeNum,
|
containerExtension: episode.containerExtension ?? 'mp4',
|
||||||
),
|
seriesId: widget.series.seriesId,
|
||||||
),
|
season: episode.seasonNum,
|
||||||
);
|
episodeNum: episode.episodeNum,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => NativePlayerScreen(
|
||||||
|
streamId: episode.streamId,
|
||||||
|
title: "${widget.series.name} S${episode.seasonNum}E${episode.episodeNum}",
|
||||||
|
playlist: widget.playlist,
|
||||||
|
streamType: StreamType.series,
|
||||||
|
containerExtension: episode.containerExtension ?? 'mp4',
|
||||||
|
seriesId: widget.series.seriesId,
|
||||||
|
season: episode.seasonNum,
|
||||||
|
episodeNum: episode.episodeNum,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:media_kit/media_kit.dart';
|
import 'package:media_kit/media_kit.dart';
|
||||||
import 'package:media_kit_video/media_kit_video.dart';
|
import 'package:media_kit_video/media_kit_video.dart';
|
||||||
|
import 'package:xtremflow/mobile/widgets/tv_focusable.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:xtremflow/core/models/iptv_models.dart';
|
import 'package:xtremflow/core/models/iptv_models.dart';
|
||||||
import 'package:xtremflow/core/models/playlist_config.dart';
|
import 'package:xtremflow/core/models/playlist_config.dart';
|
||||||
@@ -54,6 +55,13 @@ class NativePlayerScreen extends ConsumerStatefulWidget {
|
|||||||
class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with WidgetsBindingObserver {
|
class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with WidgetsBindingObserver {
|
||||||
late final Player _player;
|
late final Player _player;
|
||||||
late final VideoController _controller;
|
late final VideoController _controller;
|
||||||
|
|
||||||
|
// Focus Nodes
|
||||||
|
final FocusNode _playPauseFocusNode = FocusNode();
|
||||||
|
final FocusNode _prevFocusNode = FocusNode();
|
||||||
|
final FocusNode _nextFocusNode = FocusNode();
|
||||||
|
final FocusNode _backFocusNode = FocusNode();
|
||||||
|
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
String? _errorMessage;
|
String? _errorMessage;
|
||||||
late int _currentIndex;
|
late int _currentIndex;
|
||||||
@@ -73,12 +81,16 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
String _currentTime = '';
|
String _currentTime = '';
|
||||||
bool _hasMarkedAsWatched = false; // Flag to mark watched only once at 80%
|
bool _hasMarkedAsWatched = false; // Flag to mark watched only once at 80%
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _resetControlsTimer() {
|
void _resetControlsTimer() {
|
||||||
_controlsTimer?.cancel();
|
_controlsTimer?.cancel();
|
||||||
|
_startClock(); // Ensure clock runs when controls are shown
|
||||||
if (_showControls && _isPlaying) {
|
if (_showControls && _isPlaying) {
|
||||||
_controlsTimer = Timer(const Duration(seconds: 10), () {
|
_controlsTimer = Timer(const Duration(seconds: 10), () {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => _showControls = false);
|
setState(() => _showControls = false);
|
||||||
|
_stopClock(); // Save CPU when hidden
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -113,29 +125,37 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
_player = Player(configuration: config);
|
_player = Player(configuration: config);
|
||||||
|
|
||||||
// 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)
|
||||||
(_player.platform as dynamic)?.setProperty('hwdec', 'auto');
|
final decoderMode = ref.read(mobileSettingsProvider).decoderMode;
|
||||||
|
(_player.platform as dynamic)?.setProperty('hwdec', decoderMode);
|
||||||
|
debugPrint('MediaKitPlayer: Decoder Mode set to $decoderMode');
|
||||||
|
|
||||||
// ============ OPTIMIZED STREAM STABILITY CONFIGURATION ============
|
// ============ PERFORMANCE 2.0 (LOW MEMORY 1GB PROFILE) ============
|
||||||
// Aggressive buffering and reconnection for stable live TV playback
|
// Tuned for Low-End Android TV hardware (1GB RAM Sticks)
|
||||||
|
// Goal: Prevent OOM Kills & Crashes
|
||||||
|
|
||||||
// Large cache for smooth playback
|
// 50MB Cache = ~1 min of HD stream. Critical for 1GB RAM.
|
||||||
(_player.platform as dynamic)?.setProperty('cache', 'yes');
|
(_player.platform as dynamic)?.setProperty('cache', 'yes');
|
||||||
(_player.platform as dynamic)?.setProperty('cache-secs', '300'); // Cache up to 5 minutes
|
(_player.platform as dynamic)?.setProperty('cache-secs', '60'); // 1 minute cache
|
||||||
(_player.platform as dynamic)?.setProperty('demuxer-max-bytes', '150000000'); // 150MB max buffer
|
(_player.platform as dynamic)?.setProperty('demuxer-max-bytes', '50000000'); // 50MB buffer
|
||||||
(_player.platform as dynamic)?.setProperty('demuxer-max-back-bytes', '75000000'); // 75MB back buffer
|
(_player.platform as dynamic)?.setProperty('demuxer-max-back-bytes', '10000000'); // 10MB back buffer
|
||||||
(_player.platform as dynamic)?.setProperty('cache-pause-initial', 'yes'); // Wait for cache before playing
|
(_player.platform as dynamic)?.setProperty('cache-pause-initial', 'yes');
|
||||||
(_player.platform as dynamic)?.setProperty('cache-pause-wait', '5'); // Wait 5s minimum cache
|
(_player.platform as dynamic)?.setProperty('cache-pause-wait', '3'); // Shorter wait to start
|
||||||
|
|
||||||
|
// Standard Processing (Hardware handles it)
|
||||||
|
(_player.platform as dynamic)?.setProperty('video-sync', 'audio');
|
||||||
|
(_player.platform as dynamic)?.setProperty('interpolation', 'no'); // Keep off for safety
|
||||||
|
(_player.platform as dynamic)?.setProperty('audio-buffer', '0.5'); // Standard audio buffer
|
||||||
|
|
||||||
// Network resilience
|
// Network resilience
|
||||||
(_player.platform as dynamic)?.setProperty('network-timeout', '120'); // 2 minute timeout
|
(_player.platform as dynamic)?.setProperty('network-timeout', '120');
|
||||||
(_player.platform as dynamic)?.setProperty('stream-timeout', '120'); // 2 minute stream timeout
|
(_player.platform as dynamic)?.setProperty('stream-timeout', '120');
|
||||||
(_player.platform as dynamic)?.setProperty('tls-verify', 'no'); // Ignore SSL errors
|
(_player.platform as dynamic)?.setProperty('tls-verify', 'no');
|
||||||
(_player.platform as dynamic)?.setProperty('http-header-fields', 'User-Agent: XtremFlow/1.0');
|
(_player.platform as dynamic)?.setProperty('http-header-fields', 'User-Agent: XtremFlow/1.0');
|
||||||
|
|
||||||
// Aggressive reconnection for live streams
|
// Live Stream optimizations
|
||||||
(_player.platform as dynamic)?.setProperty('stream-lavf-o', 'reconnect=1,reconnect_streamed=1,reconnect_on_network_error=1,reconnect_on_http_error=4xx,reconnect_delay_max=10');
|
(_player.platform as dynamic)?.setProperty('stream-lavf-o', 'reconnect=1,reconnect_streamed=1,reconnect_on_network_error=1,reconnect_delay_max=5');
|
||||||
(_player.platform as dynamic)?.setProperty('force-seekable', 'yes');
|
(_player.platform as dynamic)?.setProperty('force-seekable', 'yes');
|
||||||
(_player.platform as dynamic)?.setProperty('demuxer-lavf-o', 'live_start_index=-1,analyzeduration=10000000,probesize=10000000');
|
(_player.platform as dynamic)?.setProperty('demuxer-lavf-o', 'live_start_index=-1'); // Removed large probesize
|
||||||
|
|
||||||
// Prevent stalls
|
// Prevent stalls
|
||||||
(_player.platform as dynamic)?.setProperty('demuxer-readahead-secs', '60'); // Read 60s ahead
|
(_player.platform as dynamic)?.setProperty('demuxer-readahead-secs', '60'); // Read 60s ahead
|
||||||
@@ -223,10 +243,16 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _startClock() {
|
void _startClock() {
|
||||||
|
if (_clockTimer != null && _clockTimer!.isActive) return;
|
||||||
_updateTime();
|
_updateTime();
|
||||||
_clockTimer = Timer.periodic(const Duration(seconds: 1), (_) => _updateTime());
|
_clockTimer = Timer.periodic(const Duration(seconds: 1), (_) => _updateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _stopClock() {
|
||||||
|
_clockTimer?.cancel();
|
||||||
|
_clockTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
void _updateTime() {
|
void _updateTime() {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
@@ -272,6 +298,12 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
]);
|
]);
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
|
|
||||||
|
// Dispose focus nodes
|
||||||
|
_playPauseFocusNode.dispose();
|
||||||
|
_prevFocusNode.dispose();
|
||||||
|
_nextFocusNode.dispose();
|
||||||
|
_backFocusNode.dispose();
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +507,13 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
|
|
||||||
// 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)
|
||||||
// If we are in fallback mode, force software ('no')
|
// If we are in fallback mode, force software ('no')
|
||||||
(_player.platform as dynamic)?.setProperty('hwdec', _useSoftwareDecoder ? 'no' : 'auto');
|
String hwdecValue;
|
||||||
|
if (_useSoftwareDecoder) {
|
||||||
|
hwdecValue = 'no';
|
||||||
|
} else {
|
||||||
|
hwdecValue = ref.read(mobileSettingsProvider).decoderMode;
|
||||||
|
}
|
||||||
|
(_player.platform as dynamic)?.setProperty('hwdec', hwdecValue);
|
||||||
|
|
||||||
await _player.open(
|
await _player.open(
|
||||||
Media(streamUrl, httpHeaders: {'User-Agent': 'XtremFlow/1.0'}),
|
Media(streamUrl, httpHeaders: {'User-Agent': 'XtremFlow/1.0'}),
|
||||||
@@ -566,6 +604,11 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
// Always show controls on tap, then start auto-hide timer
|
// Always show controls on tap, then start auto-hide timer
|
||||||
if (!_showControls) {
|
if (!_showControls) {
|
||||||
setState(() => _showControls = true);
|
setState(() => _showControls = true);
|
||||||
|
// Request focus on Play/Pause button when opening
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
// If controls opened, default to Play/Pause
|
||||||
|
_playPauseFocusNode.requestFocus();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
_resetControlsTimer();
|
_resetControlsTimer();
|
||||||
}
|
}
|
||||||
@@ -576,16 +619,37 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
|
|
||||||
final key = event.logicalKey;
|
final key = event.logicalKey;
|
||||||
|
|
||||||
// Space / Enter / Select - Toggle play/pause
|
// Space / Enter / Select
|
||||||
if (key == LogicalKeyboardKey.space ||
|
if (key == LogicalKeyboardKey.space ||
|
||||||
key == LogicalKeyboardKey.enter ||
|
key == LogicalKeyboardKey.enter ||
|
||||||
key == LogicalKeyboardKey.select) {
|
key == LogicalKeyboardKey.select ||
|
||||||
_togglePlayPause();
|
key == LogicalKeyboardKey.numpadEnter ||
|
||||||
return true;
|
key == LogicalKeyboardKey.gameButtonA) {
|
||||||
|
// If controls are hidden, toggle them + play/pause
|
||||||
|
if (!_showControls) {
|
||||||
|
_togglePlayPause();
|
||||||
|
_toggleControls();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// If controls are visible, let Focus system handle button press
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug Toggle: Long Press Key 'D' or 0 (if mapped) - Simplified to just a secret key combo?
|
||||||
|
// Let's use a long-press logic on Select in _handleKeyEvent?
|
||||||
|
// Actually, handling long press in key down is hard.
|
||||||
|
// We'll add a 'Debug' button in the settings or just map Key '0' if remote has it.
|
||||||
|
// Debug Toggle: Long Press Key 'D' or 0 (if mapped)
|
||||||
|
if (key == LogicalKeyboardKey.digit0) {
|
||||||
|
final current = ref.read(mobileSettingsProvider).showDebugStats;
|
||||||
|
ref.read(mobileSettingsProvider.notifier).toggleShowDebugStats(!current);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Left Arrow - Seek back 10 seconds
|
// Left Arrow - Seek back 10 seconds
|
||||||
if (key == LogicalKeyboardKey.arrowLeft) {
|
if (key == LogicalKeyboardKey.arrowLeft) {
|
||||||
|
if (_showControls) return false; // Let Focus handle navigation
|
||||||
|
|
||||||
if (widget.streamType != StreamType.live) {
|
if (widget.streamType != StreamType.live) {
|
||||||
final newPos = _position - const Duration(seconds: 10);
|
final newPos = _position - const Duration(seconds: 10);
|
||||||
_player.seek(newPos < Duration.zero ? Duration.zero : newPos);
|
_player.seek(newPos < Duration.zero ? Duration.zero : newPos);
|
||||||
@@ -596,6 +660,8 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
|
|
||||||
// Right Arrow - Seek forward 10 seconds
|
// Right Arrow - Seek forward 10 seconds
|
||||||
if (key == LogicalKeyboardKey.arrowRight) {
|
if (key == LogicalKeyboardKey.arrowRight) {
|
||||||
|
if (_showControls) return false; // Let Focus handle navigation
|
||||||
|
|
||||||
if (widget.streamType != StreamType.live) {
|
if (widget.streamType != StreamType.live) {
|
||||||
final newPos = _position + const Duration(seconds: 10);
|
final newPos = _position + const Duration(seconds: 10);
|
||||||
if (newPos < _duration) {
|
if (newPos < _duration) {
|
||||||
@@ -625,7 +691,12 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
// Escape / Back - Exit player
|
// Escape / Back - Exit player
|
||||||
if (key == LogicalKeyboardKey.escape ||
|
if (key == LogicalKeyboardKey.escape ||
|
||||||
key == LogicalKeyboardKey.goBack) {
|
key == LogicalKeyboardKey.goBack) {
|
||||||
Navigator.of(context).pop();
|
// If controls are visible, close them first
|
||||||
|
if (_showControls) {
|
||||||
|
setState(() => _showControls = false);
|
||||||
|
} else {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,22 +754,33 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
decoration: BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
gradient: LinearGradient(
|
color: Colors.black54, // Flat color instead of Gradient for performance
|
||||||
begin: Alignment.topCenter,
|
|
||||||
end: Alignment.bottomCenter,
|
|
||||||
colors: [
|
|
||||||
Colors.black.withOpacity(0.8),
|
|
||||||
Colors.transparent,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
// Main Back Button
|
// Main Back Button
|
||||||
IconButton(
|
// Main Back Button
|
||||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
TVFocusable(
|
||||||
onPressed: () => Navigator.pop(context),
|
focusNode: _backFocusNode,
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
onFocus: _resetControlsTimer,
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Hidden Debug Trigger (Invisible InkWell next to back button)
|
||||||
|
InkWell(
|
||||||
|
onLongPress: () {
|
||||||
|
final current = ref.read(mobileSettingsProvider).showDebugStats;
|
||||||
|
ref.read(mobileSettingsProvider.notifier).toggleShowDebugStats(!current);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Debug Mode: ${!current ? "ON" : "OFF"}'), duration: const Duration(seconds: 1)),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const SizedBox(width: 20, height: 40),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -734,12 +816,20 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Stats Overlay (Top Left) - Isolated to prevent main rebuilds
|
||||||
|
Positioned(
|
||||||
|
top: 80,
|
||||||
|
left: 16,
|
||||||
|
child: StatsOverlayWidget(player: _player),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String _formatDuration(Duration duration) {
|
String _formatDuration(Duration duration) {
|
||||||
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
||||||
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
|
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
|
||||||
@@ -763,46 +853,85 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
children: [
|
children: [
|
||||||
// Prev Channel / Replay 10s
|
// Prev Channel / Replay 10s
|
||||||
if (widget.streamType == StreamType.live && widget.channels != null && widget.channels!.isNotEmpty)
|
if (widget.streamType == StreamType.live && widget.channels != null && widget.channels!.isNotEmpty)
|
||||||
IconButton(
|
TVFocusable(
|
||||||
icon: const Icon(Icons.skip_previous, color: Colors.white, size: 48),
|
focusNode: _prevFocusNode,
|
||||||
onPressed: _playPrevious,
|
onPressed: _playPrevious,
|
||||||
|
onFocus: _resetControlsTimer,
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.skip_previous, color: Colors.white, size: 48),
|
||||||
|
onPressed: _playPrevious,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
else if (widget.streamType != StreamType.live)
|
else if (widget.streamType != StreamType.live)
|
||||||
IconButton(
|
TVFocusable(
|
||||||
icon: const Icon(Icons.replay_10, color: Colors.white, size: 48),
|
focusNode: _prevFocusNode,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final pos = await _player.stream.position.first;
|
final pos = await _player.stream.position.first;
|
||||||
_player.seek(pos - const Duration(seconds: 10));
|
_player.seek(pos - const Duration(seconds: 10));
|
||||||
|
_resetControlsTimer();
|
||||||
},
|
},
|
||||||
|
onFocus: _resetControlsTimer,
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.replay_10, color: Colors.white, size: 48),
|
||||||
|
onPressed: () async {
|
||||||
|
final pos = await _player.stream.position.first;
|
||||||
|
_player.seek(pos - const Duration(seconds: 10));
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(width: 32),
|
const SizedBox(width: 32),
|
||||||
|
|
||||||
// Play/Pause
|
// Play/Pause
|
||||||
IconButton(
|
TVFocusable(
|
||||||
iconSize: 72,
|
focusNode: _playPauseFocusNode,
|
||||||
icon: Icon(
|
|
||||||
_isPlaying ? Icons.pause_circle_filled : Icons.play_circle_filled,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
onPressed: _togglePlayPause,
|
onPressed: _togglePlayPause,
|
||||||
|
onFocus: _resetControlsTimer,
|
||||||
|
scale: 1.1, // Larger scale for main button
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
child: IconButton(
|
||||||
|
iconSize: 72,
|
||||||
|
icon: Icon(
|
||||||
|
_isPlaying ? Icons.pause_circle_filled : Icons.play_circle_filled,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
onPressed: _togglePlayPause,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(width: 32),
|
const SizedBox(width: 32),
|
||||||
|
|
||||||
// Next Channel / Forward 10s
|
// Next Channel / Forward 10s
|
||||||
if (widget.streamType == StreamType.live && widget.channels != null && widget.channels!.isNotEmpty)
|
if (widget.streamType == StreamType.live && widget.channels != null && widget.channels!.isNotEmpty)
|
||||||
IconButton(
|
TVFocusable(
|
||||||
icon: const Icon(Icons.skip_next, color: Colors.white, size: 48),
|
focusNode: _nextFocusNode,
|
||||||
onPressed: _playNext,
|
onPressed: _playNext,
|
||||||
|
onFocus: _resetControlsTimer,
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.skip_next, color: Colors.white, size: 48),
|
||||||
|
onPressed: _playNext,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
else if (widget.streamType != StreamType.live)
|
else if (widget.streamType != StreamType.live)
|
||||||
IconButton(
|
TVFocusable(
|
||||||
icon: const Icon(Icons.forward_10, color: Colors.white, size: 48),
|
focusNode: _nextFocusNode,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final pos = await _player.stream.position.first;
|
final pos = await _player.stream.position.first;
|
||||||
_player.seek(pos + const Duration(seconds: 10));
|
_player.seek(pos + const Duration(seconds: 10));
|
||||||
|
_resetControlsTimer();
|
||||||
},
|
},
|
||||||
|
onFocus: _resetControlsTimer,
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.forward_10, color: Colors.white, size: 48),
|
||||||
|
onPressed: () async {
|
||||||
|
final pos = await _player.stream.position.first;
|
||||||
|
_player.seek(pos + const Duration(seconds: 10));
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -1015,3 +1144,70 @@ class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> with Wi
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Isolated Stats Widget to prevent rebuilding the entire Video Player on every update
|
||||||
|
class StatsOverlayWidget extends ConsumerStatefulWidget {
|
||||||
|
final Player player;
|
||||||
|
const StatsOverlayWidget({super.key, required this.player});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<StatsOverlayWidget> createState() => _StatsOverlayWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StatsOverlayWidgetState extends ConsumerState<StatsOverlayWidget> {
|
||||||
|
Duration _buffer = Duration.zero;
|
||||||
|
String _decoder = 'Unknown';
|
||||||
|
|
||||||
|
// Throttling updates
|
||||||
|
Timer? _updateTimer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
// Use a periodic timer to poll/update stats instead of listening to every single frequent event
|
||||||
|
// This reduces UI thread load significantly on low-end devices
|
||||||
|
_updateTimer = Timer.periodic(const Duration(milliseconds: 1000), (_) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_buffer = widget.player.state.buffer;
|
||||||
|
// Accessing nested prop safely just in case
|
||||||
|
final track = widget.player.state.track.video;
|
||||||
|
_decoder = track.decoder ?? 'Auto';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_updateTimer?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (!ref.watch(mobileSettingsProvider).showDebugStats) return const SizedBox.shrink();
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black.withOpacity(0.7),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: Colors.green.withOpacity(0.5)),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Text('STATS FOR NERDS 🤓',
|
||||||
|
style: TextStyle(color: Colors.green, fontWeight: FontWeight.bold, fontSize: 12)),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text('Buffer: ${_buffer.inSeconds}s',
|
||||||
|
style: const TextStyle(color: Colors.white, fontSize: 12)),
|
||||||
|
Text('Decoder: $_decoder',
|
||||||
|
style: const TextStyle(color: Colors.white, fontSize: 12)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,9 @@ import '../../../../core/models/playlist_config.dart';
|
|||||||
import '../../../../core/theme/app_colors.dart';
|
import '../../../../core/theme/app_colors.dart';
|
||||||
import '../../../../core/api/dns_resolver.dart';
|
import '../../../../core/api/dns_resolver.dart';
|
||||||
import '../../../theme/mobile_theme.dart';
|
import '../../../theme/mobile_theme.dart';
|
||||||
|
import 'package:xtremflow/mobile/widgets/tv_focusable.dart';
|
||||||
|
import 'package:xtremflow/mobile/features/iptv/screens/lite_player_screen.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class MobileLiveTVTab extends ConsumerStatefulWidget {
|
class MobileLiveTVTab extends ConsumerStatefulWidget {
|
||||||
final PlaylistConfig playlist;
|
final PlaylistConfig playlist;
|
||||||
@@ -21,10 +24,13 @@ class MobileLiveTVTab extends ConsumerStatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with AutomaticKeepAliveClientMixin {
|
class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with AutomaticKeepAliveClientMixin {
|
||||||
String? _selectedCategory;
|
|
||||||
|
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
|
final FocusNode _searchFocusNode = FocusNode();
|
||||||
String _searchQuery = '';
|
String _searchQuery = '';
|
||||||
bool _showFavoritesOnly = false;
|
bool _showFavoritesOnly = false;
|
||||||
|
bool _isSearchEditing = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -39,10 +45,12 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_searchController.dispose();
|
_searchController.dispose();
|
||||||
|
_searchFocusNode.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isCategoryView = true;
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
@@ -53,10 +61,30 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
final channelsAsync = ref.watch(mobileLiveChannelsProvider(widget.playlist));
|
final channelsAsync = ref.watch(mobileLiveChannelsProvider(widget.playlist));
|
||||||
final favorites = ref.watch(mobileFavoritesProvider);
|
final favorites = ref.watch(mobileFavoritesProvider);
|
||||||
final settings = ref.watch(mobileSettingsProvider);
|
final settings = ref.watch(mobileSettingsProvider);
|
||||||
|
final uiState = ref.watch(mobileLiveTvUiStateProvider);
|
||||||
|
final uiNotifier = ref.read(mobileLiveTvUiStateProvider.notifier);
|
||||||
|
|
||||||
return Scaffold(
|
return Container(
|
||||||
backgroundColor: AppColors.background,
|
decoration: const BoxDecoration(gradient: AppColors.appleTvGradient),
|
||||||
body: channelsAsync.when(
|
child: Scaffold(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
body: PopScope(
|
||||||
|
canPop: uiState.isCategoryView && _searchQuery.isEmpty && !_showFavoritesOnly,
|
||||||
|
onPopInvoked: (didPop) {
|
||||||
|
if (didPop) return;
|
||||||
|
|
||||||
|
if (_searchQuery.isNotEmpty) {
|
||||||
|
setState(() {
|
||||||
|
_searchController.clear();
|
||||||
|
_searchQuery = '';
|
||||||
|
});
|
||||||
|
} else if (_showFavoritesOnly) {
|
||||||
|
setState(() => _showFavoritesOnly = false);
|
||||||
|
} else if (!uiState.isCategoryView) {
|
||||||
|
uiNotifier.state = uiState.copyWith(isCategoryView: true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: channelsAsync.when(
|
||||||
loading: () => const Center(child: CircularProgressIndicator()),
|
loading: () => const Center(child: CircularProgressIndicator()),
|
||||||
error: (e, s) => Center(
|
error: (e, s) => Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@@ -80,7 +108,7 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
List<Channel> displayedChannels = [];
|
List<Channel> displayedChannels = [];
|
||||||
|
|
||||||
// Determine mode based on search/favorites/selection
|
// Determine mode based on search/favorites/selection
|
||||||
bool showGrid = _isCategoryView && _searchQuery.isEmpty && !_showFavoritesOnly;
|
bool showGrid = uiState.isCategoryView && _searchQuery.isEmpty && !_showFavoritesOnly;
|
||||||
|
|
||||||
if (!showGrid) {
|
if (!showGrid) {
|
||||||
if (_searchQuery.isNotEmpty) {
|
if (_searchQuery.isNotEmpty) {
|
||||||
@@ -91,8 +119,8 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
displayedChannels = groupedChannels.values.expand((l) => l)
|
displayedChannels = groupedChannels.values.expand((l) => l)
|
||||||
.where((c) => favorites.contains(c.streamId))
|
.where((c) => favorites.contains(c.streamId))
|
||||||
.toList();
|
.toList();
|
||||||
} else if (_selectedCategory != null) {
|
} else if (uiState.selectedCategory != null) {
|
||||||
displayedChannels = groupedChannels[_selectedCategory] ?? [];
|
displayedChannels = groupedChannels[uiState.selectedCategory] ?? [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,34 +134,49 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// Search Bar
|
// Search Bar
|
||||||
Container(
|
GestureDetector(
|
||||||
height: 48,
|
onTap: () {
|
||||||
decoration: BoxDecoration(
|
setState(() => _isSearchEditing = true);
|
||||||
color: AppColors.surface,
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
borderRadius: BorderRadius.circular(12),
|
_searchFocusNode.requestFocus();
|
||||||
),
|
});
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
},
|
||||||
child: Row(
|
child: Container(
|
||||||
children: [
|
height: 48,
|
||||||
const Icon(Icons.search, color: AppColors.textSecondary),
|
decoration: BoxDecoration(
|
||||||
const SizedBox(width: 8),
|
color: AppColors.surface,
|
||||||
Expanded(
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: TextField(
|
border: _isSearchEditing ? Border.all(color: AppColors.primary) : null,
|
||||||
controller: _searchController,
|
),
|
||||||
style: const TextStyle(color: AppColors.textPrimary),
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
decoration: const InputDecoration(
|
child: Row(
|
||||||
hintText: 'Rechercher une chaîne...',
|
children: [
|
||||||
border: InputBorder.none,
|
const Icon(Icons.search, color: AppColors.textSecondary),
|
||||||
isDense: true,
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: ExcludeFocus(
|
||||||
|
excluding: !_isSearchEditing,
|
||||||
|
child: TextField(
|
||||||
|
controller: _searchController,
|
||||||
|
focusNode: _searchFocusNode,
|
||||||
|
readOnly: !_isSearchEditing,
|
||||||
|
style: const TextStyle(color: AppColors.textPrimary),
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Rechercher une chaîne...',
|
||||||
|
border: InputBorder.none,
|
||||||
|
isDense: true,
|
||||||
|
),
|
||||||
|
onSubmitted: (_) => setState(() => _isSearchEditing = false),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
if (_searchQuery.isNotEmpty)
|
||||||
if (_searchQuery.isNotEmpty)
|
GestureDetector(
|
||||||
GestureDetector(
|
onTap: () => _searchController.clear(),
|
||||||
onTap: () => _searchController.clear(),
|
child: const Icon(Icons.close, color: AppColors.textSecondary),
|
||||||
child: const Icon(Icons.close, color: AppColors.textSecondary),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -151,7 +194,7 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
} else if (_showFavoritesOnly) {
|
} else if (_showFavoritesOnly) {
|
||||||
setState(() => _showFavoritesOnly = false);
|
setState(() => _showFavoritesOnly = false);
|
||||||
} else {
|
} else {
|
||||||
setState(() => _isCategoryView = true);
|
uiNotifier.state = uiState.copyWith(isCategoryView: true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
@@ -164,7 +207,7 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
_searchQuery.isNotEmpty ? 'Résultats de recherche' :
|
_searchQuery.isNotEmpty ? 'Résultats de recherche' :
|
||||||
_showFavoritesOnly ? 'Favoris' :
|
_showFavoritesOnly ? 'Favoris' :
|
||||||
showGrid ? 'Catégories' :
|
showGrid ? 'Catégories' :
|
||||||
_selectedCategory ?? 'Chaînes',
|
uiState.selectedCategory ?? 'Chaînes',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: AppColors.textPrimary,
|
color: AppColors.textPrimary,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@@ -181,9 +224,9 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
onPressed: () => setState(() {
|
onPressed: () => setState(() {
|
||||||
_showFavoritesOnly = !_showFavoritesOnly;
|
_showFavoritesOnly = !_showFavoritesOnly;
|
||||||
// Reset category view if entering favorites
|
// Reset category view if entering favorites
|
||||||
if (_showFavoritesOnly) _isCategoryView = false;
|
if (_showFavoritesOnly) uiNotifier.state = uiState.copyWith(isCategoryView: false);
|
||||||
// If exiting favorites, default depends on logic (here back to category grid if was previously)
|
// If exiting favorites, default depends on logic (here back to category grid if was previously)
|
||||||
if (!_showFavoritesOnly) _isCategoryView = true;
|
if (!_showFavoritesOnly) uiNotifier.state = uiState.copyWith(isCategoryView: true);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -203,6 +246,8 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,12 +272,12 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
itemCount: categories.length,
|
itemCount: categories.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final category = categories[index];
|
final category = categories[index];
|
||||||
return InkWell(
|
return TVFocusable(
|
||||||
onTap: () {
|
onPressed: () {
|
||||||
setState(() {
|
ref.read(mobileLiveTvUiStateProvider.notifier).state = LiveTvUiState(
|
||||||
_selectedCategory = category;
|
selectedCategory: category,
|
||||||
_isCategoryView = false;
|
isCategoryView: false,
|
||||||
});
|
);
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
child: Container(
|
child: Container(
|
||||||
@@ -303,25 +348,44 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab> with Automati
|
|||||||
return _MobileChannelTile(
|
return _MobileChannelTile(
|
||||||
channel: channel,
|
channel: channel,
|
||||||
playlist: widget.playlist,
|
playlist: widget.playlist,
|
||||||
onTap: () => _playChannel(context, channel, channels),
|
onTap: () => _playChannel(context, channel, channels, widget.playlist, index),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _playChannel(BuildContext context, Channel channel, List<Channel> channels) {
|
void _playChannel(BuildContext context, Channel channel, List<Channel> channels, PlaylistConfig playlist, int index) {
|
||||||
Navigator.of(context).push(
|
final engine = ref.read(mobileSettingsProvider).playerEngine;
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => NativePlayerScreen(
|
if (engine == 'lite') {
|
||||||
streamId: channel.streamId,
|
Navigator.push(
|
||||||
title: channel.name,
|
context,
|
||||||
playlist: widget.playlist,
|
MaterialPageRoute(
|
||||||
streamType: StreamType.live,
|
builder: (context) => LitePlayerScreen(
|
||||||
channels: channels,
|
streamId: channel.streamId,
|
||||||
initialIndex: channels.indexOf(channel),
|
title: channel.name,
|
||||||
),
|
playlist: playlist,
|
||||||
),
|
streamType: StreamType.live,
|
||||||
);
|
channels: channels, // Pass full channel list for zapping
|
||||||
|
initialIndex: index,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,8 +439,8 @@ class _MobileChannelTileState extends ConsumerState<_MobileChannelTile> {
|
|||||||
final favorites = ref.watch(mobileFavoritesProvider);
|
final favorites = ref.watch(mobileFavoritesProvider);
|
||||||
final isFavorite = favorites.contains(widget.channel.streamId);
|
final isFavorite = favorites.contains(widget.channel.streamId);
|
||||||
|
|
||||||
return InkWell(
|
return TVFocusable(
|
||||||
onTap: widget.onTap,
|
onPressed: widget.onTap,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:xtremflow/mobile/widgets/tv_focusable.dart';
|
||||||
import '../../../../core/models/playlist_config.dart';
|
import '../../../../core/models/playlist_config.dart';
|
||||||
import '../../../../core/theme/app_colors.dart';
|
import '../../../../core/theme/app_colors.dart';
|
||||||
import '../../../../core/widgets/components/hero_carousel.dart';
|
import '../../../../core/widgets/components/hero_carousel.dart';
|
||||||
@@ -9,6 +11,7 @@ import '../../../providers/mobile_settings_providers.dart';
|
|||||||
import '../../../providers/mobile_xtream_providers.dart';
|
import '../../../providers/mobile_xtream_providers.dart';
|
||||||
import '../../../../features/iptv/services/xtream_service_mobile.dart';
|
import '../../../../features/iptv/services/xtream_service_mobile.dart';
|
||||||
import '../screens/native_player_screen.dart';
|
import '../screens/native_player_screen.dart';
|
||||||
|
import '../screens/lite_player_screen.dart';
|
||||||
|
|
||||||
class MobileMoviesTab extends ConsumerStatefulWidget {
|
class MobileMoviesTab extends ConsumerStatefulWidget {
|
||||||
final PlaylistConfig playlist;
|
final PlaylistConfig playlist;
|
||||||
@@ -21,9 +24,11 @@ class MobileMoviesTab extends ConsumerStatefulWidget {
|
|||||||
class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab> with AutomaticKeepAliveClientMixin {
|
class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab> with AutomaticKeepAliveClientMixin {
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
|
final FocusNode _searchFocusNode = FocusNode();
|
||||||
final List<Movie> _movies = [];
|
final List<Movie> _movies = [];
|
||||||
List<Movie>? _searchResults;
|
List<Movie>? _searchResults;
|
||||||
String _searchQuery = '';
|
String _searchQuery = '';
|
||||||
|
bool _isSearchEditing = false;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
bool _isSearching = false;
|
bool _isSearching = false;
|
||||||
bool _hasMore = true;
|
bool _hasMore = true;
|
||||||
@@ -42,6 +47,7 @@ class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab> with Automati
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_scrollController.dispose();
|
_scrollController.dispose();
|
||||||
_searchController.dispose();
|
_searchController.dispose();
|
||||||
|
_searchFocusNode.dispose();
|
||||||
_searchDebounce?.cancel();
|
_searchDebounce?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@@ -159,20 +165,38 @@ class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab> with Automati
|
|||||||
return originalUrl;
|
return originalUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _playMovie(Movie movie) {
|
void _playMovie(BuildContext context, Movie movie) {
|
||||||
// Watch progress is tracked in player at 80% completion
|
if (widget.playlist == null) return;
|
||||||
Navigator.push(
|
|
||||||
context,
|
final engine = ref.read(mobileSettingsProvider).playerEngine;
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => NativePlayerScreen(
|
if (engine == 'lite') {
|
||||||
streamId: movie.streamId,
|
Navigator.push(
|
||||||
title: movie.name,
|
context,
|
||||||
playlist: widget.playlist,
|
MaterialPageRoute(
|
||||||
streamType: StreamType.vod,
|
builder: (context) => LitePlayerScreen(
|
||||||
containerExtension: movie.containerExtension ?? 'mp4',
|
streamId: movie.streamId,
|
||||||
|
title: movie.name,
|
||||||
|
playlist: widget.playlist!,
|
||||||
|
streamType: StreamType.vod,
|
||||||
|
containerExtension: movie.containerExtension,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
} else {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => NativePlayerScreen(
|
||||||
|
streamId: movie.streamId,
|
||||||
|
title: movie.name,
|
||||||
|
playlist: widget.playlist!,
|
||||||
|
streamType: StreamType.vod,
|
||||||
|
containerExtension: movie.containerExtension,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -198,131 +222,153 @@ class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab> with Automati
|
|||||||
id: m.streamId,
|
id: m.streamId,
|
||||||
title: m.name,
|
title: m.name,
|
||||||
imageUrl: _getImageUrl(m.streamIcon),
|
imageUrl: _getImageUrl(m.streamIcon),
|
||||||
subtitle: m.rating != null ? '${_formatRating(m.rating)} ★' : null,
|
subtitle: m.rating != null ? '${_formatRating(m.rating)} ★' : null,
|
||||||
onMoreInfo: () => _playMovie(m),
|
onMoreInfo: () => _playMovie(context, m),
|
||||||
)).toList();
|
)).toList();
|
||||||
|
|
||||||
return SafeArea(
|
return Container(
|
||||||
bottom: false,
|
decoration: const BoxDecoration(gradient: AppColors.appleTvGradient),
|
||||||
child: RefreshIndicator(
|
child: SafeArea(
|
||||||
onRefresh: _refresh,
|
bottom: false,
|
||||||
color: AppColors.primary,
|
child: RefreshIndicator(
|
||||||
backgroundColor: AppColors.surface,
|
onRefresh: _refresh,
|
||||||
child: CustomScrollView(
|
color: AppColors.primary,
|
||||||
controller: _scrollController,
|
backgroundColor: AppColors.surface,
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
child: CustomScrollView(
|
||||||
slivers: [
|
controller: _scrollController,
|
||||||
// Header & Search
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
SliverToBoxAdapter(
|
slivers: [
|
||||||
child: Padding(
|
// Header & Search
|
||||||
padding: const EdgeInsets.all(16),
|
SliverToBoxAdapter(
|
||||||
child: Container(
|
child: Padding(
|
||||||
height: 40,
|
padding: const EdgeInsets.all(16),
|
||||||
decoration: BoxDecoration(
|
child: GestureDetector(
|
||||||
color: AppColors.surface,
|
onTap: () {
|
||||||
borderRadius: BorderRadius.circular(12),
|
setState(() => _isSearchEditing = true);
|
||||||
border: Border.all(color: AppColors.border),
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
),
|
_searchFocusNode.requestFocus();
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
});
|
||||||
child: Row(
|
},
|
||||||
children: [
|
child: Container(
|
||||||
const Icon(Icons.search, size: 20, color: AppColors.textSecondary),
|
height: 40,
|
||||||
const SizedBox(width: 8),
|
decoration: BoxDecoration(
|
||||||
Expanded(
|
color: AppColors.surface,
|
||||||
child: TextField(
|
borderRadius: BorderRadius.circular(12),
|
||||||
controller: _searchController,
|
border: _isSearchEditing
|
||||||
style: const TextStyle(fontSize: 14, color: AppColors.textPrimary),
|
? Border.all(color: AppColors.primary)
|
||||||
decoration: const InputDecoration(
|
: Border.all(color: AppColors.border),
|
||||||
hintText: 'Search Movies',
|
),
|
||||||
border: InputBorder.none,
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
isDense: true,
|
child: Row(
|
||||||
contentPadding: EdgeInsets.only(bottom: 11),
|
children: [
|
||||||
),
|
const Icon(Icons.search, size: 20, color: AppColors.textSecondary),
|
||||||
onChanged: _onSearchChanged,
|
const SizedBox(width: 8),
|
||||||
),
|
Expanded(
|
||||||
),
|
child: ExcludeFocus(
|
||||||
if (_isSearching)
|
excluding: !_isSearchEditing,
|
||||||
const SizedBox(width: 12, height: 12, child: CircularProgressIndicator(strokeWidth: 2)),
|
child: TextField(
|
||||||
if (_searchQuery.isNotEmpty)
|
controller: _searchController,
|
||||||
GestureDetector(
|
focusNode: _searchFocusNode,
|
||||||
onTap: () {
|
readOnly: !_isSearchEditing,
|
||||||
_searchController.clear();
|
style: const TextStyle(fontSize: 14, color: AppColors.textPrimary),
|
||||||
_onSearchChanged('');
|
decoration: const InputDecoration(
|
||||||
},
|
hintText: 'Search Movies',
|
||||||
child: const Icon(Icons.close, size: 16, color: AppColors.textSecondary),
|
border: InputBorder.none,
|
||||||
),
|
isDense: true,
|
||||||
],
|
contentPadding: EdgeInsets.only(bottom: 11),
|
||||||
),
|
),
|
||||||
),
|
onChanged: _onSearchChanged,
|
||||||
),
|
onSubmitted: (_) => setState(() => _isSearchEditing = false),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
// Hero Section
|
),
|
||||||
if (_searchQuery.isEmpty && heroItems.isNotEmpty)
|
if (_isSearching)
|
||||||
SliverToBoxAdapter(
|
const SizedBox(width: 12, height: 12, child: CircularProgressIndicator(strokeWidth: 2)),
|
||||||
child: Padding(
|
if (_searchQuery.isNotEmpty)
|
||||||
padding: const EdgeInsets.only(bottom: 16),
|
GestureDetector(
|
||||||
child: SizedBox(
|
onTap: () {
|
||||||
height: 250,
|
_searchController.clear();
|
||||||
child: HeroCarousel(
|
_onSearchChanged('');
|
||||||
items: heroItems,
|
},
|
||||||
onTap: (item) {
|
child: const Icon(Icons.close, size: 16, color: AppColors.textSecondary),
|
||||||
try {
|
),
|
||||||
final movie = _movies.firstWhere((element) => element.streamId == item.id);
|
],
|
||||||
_playMovie(movie);
|
),
|
||||||
} catch (e) {
|
|
||||||
// Fallback ignored
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Grid
|
|
||||||
SliverPadding(
|
|
||||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 80),
|
|
||||||
sliver: SliverGrid(
|
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
||||||
crossAxisCount: 8,
|
|
||||||
crossAxisSpacing: 8,
|
|
||||||
mainAxisSpacing: 8,
|
|
||||||
childAspectRatio: 0.7,
|
|
||||||
),
|
|
||||||
delegate: SliverChildBuilderDelegate(
|
|
||||||
(context, index) {
|
|
||||||
if (index >= displayMovies.length) return null;
|
|
||||||
final movie = displayMovies[index];
|
|
||||||
final isWatched = watchHistory.isMovieWatched(movie.streamId);
|
|
||||||
|
|
||||||
return MediaCard(
|
|
||||||
title: movie.name,
|
|
||||||
imageUrl: _getImageUrl(movie.streamIcon),
|
|
||||||
|
|
||||||
subtitle: movie.rating != null ? '${_formatRating(movie.rating)} ★' : null,
|
// Hero Section
|
||||||
rating: _formatRating(movie.rating),
|
if (_searchQuery.isEmpty && heroItems.isNotEmpty)
|
||||||
isWatched: isWatched,
|
SliverToBoxAdapter(
|
||||||
onTap: () => _playMovie(movie),
|
child: Padding(
|
||||||
onLongPress: () {
|
padding: const EdgeInsets.only(bottom: 16),
|
||||||
ref.read(mobileWatchHistoryProvider.notifier).toggleMovieWatched(movie.streamId);
|
child: SizedBox(
|
||||||
},
|
height: 250,
|
||||||
);
|
child: HeroCarousel(
|
||||||
},
|
items: heroItems,
|
||||||
childCount: displayMovies.length,
|
onTap: (item) {
|
||||||
),
|
try {
|
||||||
),
|
final movie = _movies.firstWhere((element) => element.streamId == item.id);
|
||||||
),
|
_playMovie(context, movie);
|
||||||
|
} catch (e) {
|
||||||
if (_isLoading)
|
// Fallback ignored
|
||||||
const SliverToBoxAdapter(
|
}
|
||||||
child: Padding(
|
},
|
||||||
padding: EdgeInsets.all(24),
|
),
|
||||||
child: Center(child: CircularProgressIndicator()),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
// Grid
|
||||||
),
|
SliverPadding(
|
||||||
);
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 80),
|
||||||
|
sliver: SliverGrid(
|
||||||
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: 8,
|
||||||
|
crossAxisSpacing: 8,
|
||||||
|
mainAxisSpacing: 8,
|
||||||
|
childAspectRatio: 0.7,
|
||||||
|
),
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(context, index) {
|
||||||
|
if (index >= displayMovies.length) return null;
|
||||||
|
final movie = displayMovies[index];
|
||||||
|
final isWatched = watchHistory.isMovieWatched(movie.streamId);
|
||||||
|
|
||||||
|
return TVFocusable(
|
||||||
|
onPressed: () => _playMovie(context, movie),
|
||||||
|
child: MediaCard(
|
||||||
|
title: movie.name,
|
||||||
|
imageUrl: _getImageUrl(movie.streamIcon),
|
||||||
|
subtitle: movie.rating != null ? '${_formatRating(movie.rating)} ★' : null,
|
||||||
|
rating: _formatRating(movie.rating),
|
||||||
|
isWatched: isWatched,
|
||||||
|
onTap: () => _playMovie(context, movie),
|
||||||
|
onLongPress: () {
|
||||||
|
ref.read(mobileWatchHistoryProvider.notifier).toggleMovieWatched(movie.streamId);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
childCount: displayMovies.length,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
if (_isLoading)
|
||||||
|
const SliverToBoxAdapter(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(24),
|
||||||
|
child: Center(child: CircularProgressIndicator()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:xtremflow/mobile/widgets/tv_focusable.dart';
|
||||||
import '../../../../core/models/playlist_config.dart';
|
import '../../../../core/models/playlist_config.dart';
|
||||||
import '../../../../core/theme/app_colors.dart';
|
import '../../../../core/theme/app_colors.dart';
|
||||||
import '../../../../core/widgets/components/hero_carousel.dart';
|
import '../../../../core/widgets/components/hero_carousel.dart';
|
||||||
@@ -21,9 +23,11 @@ class MobileSeriesTab extends ConsumerStatefulWidget {
|
|||||||
class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab> with AutomaticKeepAliveClientMixin {
|
class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab> with AutomaticKeepAliveClientMixin {
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
|
final FocusNode _searchFocusNode = FocusNode();
|
||||||
final List<Series> _series = [];
|
final List<Series> _series = [];
|
||||||
List<Series>? _searchResults;
|
List<Series>? _searchResults;
|
||||||
String _searchQuery = '';
|
String _searchQuery = '';
|
||||||
|
bool _isSearchEditing = false;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
bool _isSearching = false;
|
bool _isSearching = false;
|
||||||
bool _hasMore = true;
|
bool _hasMore = true;
|
||||||
@@ -42,6 +46,7 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab> with Automati
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_scrollController.dispose();
|
_scrollController.dispose();
|
||||||
_searchController.dispose();
|
_searchController.dispose();
|
||||||
|
_searchFocusNode.dispose();
|
||||||
_searchDebounce?.cancel();
|
_searchDebounce?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@@ -197,7 +202,9 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab> with Automati
|
|||||||
onMoreInfo: () => _openSeries(s),
|
onMoreInfo: () => _openSeries(s),
|
||||||
)).toList();
|
)).toList();
|
||||||
|
|
||||||
return SafeArea(
|
return Container(
|
||||||
|
decoration: const BoxDecoration(gradient: AppColors.appleTvGradient),
|
||||||
|
child: SafeArea(
|
||||||
bottom: false,
|
bottom: false,
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: _refresh,
|
onRefresh: _refresh,
|
||||||
@@ -209,47 +216,63 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab> with Automati
|
|||||||
slivers: [
|
slivers: [
|
||||||
// Header & Search
|
// Header & Search
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Container(
|
child: GestureDetector(
|
||||||
height: 40,
|
onTap: () {
|
||||||
decoration: BoxDecoration(
|
setState(() => _isSearchEditing = true);
|
||||||
color: AppColors.surface,
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
borderRadius: BorderRadius.circular(12),
|
_searchFocusNode.requestFocus();
|
||||||
border: Border.all(color: AppColors.border),
|
});
|
||||||
),
|
},
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
child: Container(
|
||||||
child: Row(
|
height: 40,
|
||||||
children: [
|
decoration: BoxDecoration(
|
||||||
const Icon(Icons.search, size: 20, color: AppColors.textSecondary),
|
color: AppColors.surface,
|
||||||
const SizedBox(width: 8),
|
borderRadius: BorderRadius.circular(12),
|
||||||
Expanded(
|
border: _isSearchEditing
|
||||||
child: TextField(
|
? Border.all(color: AppColors.primary)
|
||||||
controller: _searchController,
|
: Border.all(color: AppColors.border),
|
||||||
style: const TextStyle(fontSize: 14, color: AppColors.textPrimary),
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
hintText: 'Search Series',
|
|
||||||
border: InputBorder.none,
|
|
||||||
isDense: true,
|
|
||||||
contentPadding: EdgeInsets.only(bottom: 11),
|
|
||||||
),
|
|
||||||
onChanged: _onSearchChanged,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
if (_isSearching)
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
const SizedBox(width: 12, height: 12, child: CircularProgressIndicator(strokeWidth: 2)),
|
child: Row(
|
||||||
if (_searchQuery.isNotEmpty)
|
children: [
|
||||||
GestureDetector(
|
const Icon(Icons.search, size: 20, color: AppColors.textSecondary),
|
||||||
onTap: () {
|
const SizedBox(width: 8),
|
||||||
_searchController.clear();
|
Expanded(
|
||||||
_onSearchChanged('');
|
child: ExcludeFocus(
|
||||||
},
|
excluding: !_isSearchEditing,
|
||||||
child: const Icon(Icons.close, size: 16, color: AppColors.textSecondary),
|
child: TextField(
|
||||||
),
|
controller: _searchController,
|
||||||
],
|
focusNode: _searchFocusNode,
|
||||||
|
readOnly: !_isSearchEditing,
|
||||||
|
style: const TextStyle(fontSize: 14, color: AppColors.textPrimary),
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Search Series',
|
||||||
|
border: InputBorder.none,
|
||||||
|
isDense: true,
|
||||||
|
contentPadding: EdgeInsets.only(bottom: 11),
|
||||||
|
),
|
||||||
|
onChanged: _onSearchChanged,
|
||||||
|
onSubmitted: (_) => setState(() => _isSearchEditing = false),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (_isSearching)
|
||||||
|
const SizedBox(width: 12, height: 12, child: CircularProgressIndicator(strokeWidth: 2)),
|
||||||
|
if (_searchQuery.isNotEmpty)
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
_searchController.clear();
|
||||||
|
_onSearchChanged('');
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.close, size: 16, color: AppColors.textSecondary),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
// Hero Section
|
// Hero Section
|
||||||
@@ -293,14 +316,17 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab> with Automati
|
|||||||
if (index >= displaySeries.length) return null;
|
if (index >= displaySeries.length) return null;
|
||||||
final series = displaySeries[index];
|
final series = displaySeries[index];
|
||||||
|
|
||||||
return MediaCard(
|
return TVFocusable(
|
||||||
title: series.name,
|
onPressed: () => _openSeries(series),
|
||||||
imageUrl: _getImageUrl(series.cover),
|
child: MediaCard(
|
||||||
|
title: series.name,
|
||||||
subtitle: series.rating != null ? '${_formatRating(series.rating)} ★' : null,
|
imageUrl: _getImageUrl(series.cover),
|
||||||
rating: _formatRating(series.rating),
|
|
||||||
placeholderIcon: Icons.tv,
|
subtitle: series.rating != null ? '${_formatRating(series.rating)} ★' : null,
|
||||||
onTap: () => _openSeries(series),
|
rating: _formatRating(series.rating),
|
||||||
|
placeholderIcon: Icons.tv,
|
||||||
|
onTap: () => _openSeries(series),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
childCount: displaySeries.length,
|
childCount: displaySeries.length,
|
||||||
@@ -318,6 +344,7 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab> with Automati
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import 'package:google_fonts/google_fonts.dart';
|
|||||||
import '../../../providers/mobile_settings_providers.dart';
|
import '../../../providers/mobile_settings_providers.dart';
|
||||||
import '../../../../core/providers/theme_provider.dart';
|
import '../../../../core/providers/theme_provider.dart';
|
||||||
import '../../../../core/theme/app_colors.dart';
|
import '../../../../core/theme/app_colors.dart';
|
||||||
|
import '../screens/mobile_playlist_selection_screen.dart';
|
||||||
|
|
||||||
/// Simplified mobile settings tab - no auth, local storage only
|
/// Simplified mobile settings tab - no auth, local storage only
|
||||||
class MobileSettingsTab extends ConsumerStatefulWidget {
|
class MobileSettingsTab extends ConsumerStatefulWidget {
|
||||||
@@ -167,6 +168,69 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
|
|||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.rocket_launch, color: AppColors.primary),
|
||||||
|
title: const Text('Moteur Vidéo',
|
||||||
|
style: TextStyle(color: AppColors.textPrimary)),
|
||||||
|
subtitle: Text(
|
||||||
|
settings.playerEngine == 'ultra' ? 'Ultra (MPV) - Puissant' : 'Lite (ExoPlayer) - Léger',
|
||||||
|
style: const TextStyle(color: AppColors.textSecondary),
|
||||||
|
),
|
||||||
|
trailing: DropdownButton<String>(
|
||||||
|
value: settings.playerEngine,
|
||||||
|
dropdownColor: AppColors.surface,
|
||||||
|
underline: const SizedBox(),
|
||||||
|
icon: const Icon(Icons.arrow_drop_down, color: AppColors.primary),
|
||||||
|
items: const [
|
||||||
|
DropdownMenuItem(value: 'ultra', child: Text('Ultra', style: TextStyle(color: AppColors.textPrimary))),
|
||||||
|
DropdownMenuItem(value: 'lite', child: Text('Lite', style: TextStyle(color: AppColors.textPrimary))),
|
||||||
|
],
|
||||||
|
onChanged: (val) {
|
||||||
|
if (val != null) {
|
||||||
|
ref.read(mobileSettingsProvider.notifier).setPlayerEngine(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Divider(height: 1, color: AppColors.textSecondary.withOpacity(0.2)),
|
||||||
|
SwitchListTile(
|
||||||
|
title: const Text('Stats pour Nerds',
|
||||||
|
style: TextStyle(color: AppColors.textPrimary)),
|
||||||
|
subtitle: const Text('Infos techniques (FPS, Buffer)',
|
||||||
|
style: TextStyle(color: AppColors.textSecondary, fontSize: 12)),
|
||||||
|
secondary: const Icon(Icons.bug_report, color: AppColors.primary),
|
||||||
|
value: settings.showDebugStats,
|
||||||
|
onChanged: (val) => ref.read(mobileSettingsProvider.notifier).toggleShowDebugStats(val),
|
||||||
|
activeColor: AppColors.primary,
|
||||||
|
),
|
||||||
|
Divider(height: 1, color: AppColors.textSecondary.withOpacity(0.2)),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.memory, color: AppColors.primary),
|
||||||
|
title: const Text('Décodeur Vidéo',
|
||||||
|
style: TextStyle(color: AppColors.textPrimary)),
|
||||||
|
subtitle: Text(
|
||||||
|
settings.decoderMode == 'auto' ? 'Automatique (Recommandé)' :
|
||||||
|
settings.decoderMode == 'mediacodec' ? 'Matériel (Hardware)' : 'Logiciel (Software)',
|
||||||
|
style: const TextStyle(color: AppColors.textSecondary),
|
||||||
|
),
|
||||||
|
trailing: DropdownButton<String>(
|
||||||
|
value: settings.decoderMode,
|
||||||
|
dropdownColor: AppColors.surface,
|
||||||
|
underline: const SizedBox(),
|
||||||
|
icon: const Icon(Icons.arrow_drop_down, color: AppColors.primary),
|
||||||
|
items: const [
|
||||||
|
DropdownMenuItem(value: 'auto', child: Text('Auto', style: TextStyle(color: AppColors.textPrimary))),
|
||||||
|
DropdownMenuItem(value: 'mediacodec', child: Text('Hardware', style: TextStyle(color: AppColors.textPrimary))),
|
||||||
|
DropdownMenuItem(value: 'no', child: Text('Software', style: TextStyle(color: AppColors.textPrimary))),
|
||||||
|
],
|
||||||
|
onChanged: (val) {
|
||||||
|
if (val != null) {
|
||||||
|
ref.read(mobileSettingsProvider.notifier).setDecoderMode(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Divider(height: 1, color: AppColors.textSecondary.withOpacity(0.2)),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.speed, color: AppColors.primary),
|
leading: const Icon(Icons.speed, color: AppColors.primary),
|
||||||
title: const Text('Mise en mémoire tampon (Cache)',
|
title: const Text('Mise en mémoire tampon (Cache)',
|
||||||
@@ -259,8 +323,13 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
|
|||||||
// Change Playlist
|
// Change Playlist
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Navigate back to playlist selection
|
// Open Playlist Selection in Manage Mode
|
||||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => const MobilePlaylistSelectionScreen(manageMode: true),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: Container(
|
child: Container(
|
||||||
@@ -274,7 +343,7 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
|
|||||||
Icon(Icons.playlist_play, color: AppColors.textPrimary),
|
Icon(Icons.playlist_play, color: AppColors.textPrimary),
|
||||||
SizedBox(width: 16),
|
SizedBox(width: 16),
|
||||||
Text(
|
Text(
|
||||||
'Changer de Playlist',
|
'Gérer les Playlists',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: AppColors.textPrimary,
|
color: AppColors.textPrimary,
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ class MobileSettings {
|
|||||||
final List<String> moviesKeywords;
|
final List<String> moviesKeywords;
|
||||||
final List<String> seriesKeywords;
|
final List<String> seriesKeywords;
|
||||||
final bool showClock;
|
final bool showClock;
|
||||||
|
final bool showDebugStats;
|
||||||
|
final String decoderMode; // 'auto', 'mediacodec' (HW), 'no' (SW)
|
||||||
|
final String playerEngine; // 'ultra' (MPV), 'lite' (ExoPlayer)
|
||||||
final int bufferDuration; // seconds, 0 = auto
|
final int bufferDuration; // seconds, 0 = auto
|
||||||
|
|
||||||
const MobileSettings({
|
const MobileSettings({
|
||||||
@@ -16,6 +19,9 @@ class MobileSettings {
|
|||||||
this.moviesKeywords = const [],
|
this.moviesKeywords = const [],
|
||||||
this.seriesKeywords = const [],
|
this.seriesKeywords = const [],
|
||||||
this.showClock = false,
|
this.showClock = false,
|
||||||
|
this.showDebugStats = false,
|
||||||
|
this.decoderMode = 'auto',
|
||||||
|
this.playerEngine = 'ultra',
|
||||||
this.bufferDuration = 0,
|
this.bufferDuration = 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -24,6 +30,9 @@ class MobileSettings {
|
|||||||
List<String>? moviesKeywords,
|
List<String>? moviesKeywords,
|
||||||
List<String>? seriesKeywords,
|
List<String>? seriesKeywords,
|
||||||
bool? showClock,
|
bool? showClock,
|
||||||
|
bool? showDebugStats,
|
||||||
|
String? decoderMode,
|
||||||
|
String? playerEngine,
|
||||||
int? bufferDuration,
|
int? bufferDuration,
|
||||||
}) {
|
}) {
|
||||||
return MobileSettings(
|
return MobileSettings(
|
||||||
@@ -31,6 +40,9 @@ class MobileSettings {
|
|||||||
moviesKeywords: moviesKeywords ?? this.moviesKeywords,
|
moviesKeywords: moviesKeywords ?? this.moviesKeywords,
|
||||||
seriesKeywords: seriesKeywords ?? this.seriesKeywords,
|
seriesKeywords: seriesKeywords ?? this.seriesKeywords,
|
||||||
showClock: showClock ?? this.showClock,
|
showClock: showClock ?? this.showClock,
|
||||||
|
showDebugStats: showDebugStats ?? this.showDebugStats,
|
||||||
|
decoderMode: decoderMode ?? this.decoderMode,
|
||||||
|
playerEngine: playerEngine ?? this.playerEngine,
|
||||||
bufferDuration: bufferDuration ?? this.bufferDuration,
|
bufferDuration: bufferDuration ?? this.bufferDuration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -78,6 +90,9 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
|
|||||||
final movies = _box?.get('moviesKeywords', defaultValue: <String>[]) as List?;
|
final movies = _box?.get('moviesKeywords', defaultValue: <String>[]) as List?;
|
||||||
final series = _box?.get('seriesKeywords', defaultValue: <String>[]) as List?;
|
final series = _box?.get('seriesKeywords', defaultValue: <String>[]) as List?;
|
||||||
final showClock = _box?.get('showClock', defaultValue: false) as bool?;
|
final showClock = _box?.get('showClock', defaultValue: false) as bool?;
|
||||||
|
final showDebugStats = _box?.get('showDebugStats', defaultValue: false) as bool?;
|
||||||
|
final decoderMode = _box?.get('decoderMode', defaultValue: 'auto') as String?;
|
||||||
|
final playerEngine = _box?.get('playerEngine', defaultValue: 'ultra') as String?;
|
||||||
final buffer = _box?.get('bufferDuration', defaultValue: 0) as int?;
|
final buffer = _box?.get('bufferDuration', defaultValue: 0) as int?;
|
||||||
|
|
||||||
state = MobileSettings(
|
state = MobileSettings(
|
||||||
@@ -85,6 +100,9 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
|
|||||||
moviesKeywords: movies?.cast<String>() ?? [],
|
moviesKeywords: movies?.cast<String>() ?? [],
|
||||||
seriesKeywords: series?.cast<String>() ?? [],
|
seriesKeywords: series?.cast<String>() ?? [],
|
||||||
showClock: showClock ?? false,
|
showClock: showClock ?? false,
|
||||||
|
showDebugStats: showDebugStats ?? false,
|
||||||
|
decoderMode: decoderMode ?? 'auto',
|
||||||
|
playerEngine: playerEngine ?? 'ultra',
|
||||||
bufferDuration: buffer ?? 0,
|
bufferDuration: buffer ?? 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -109,6 +127,21 @@ class MobileSettingsNotifier extends StateNotifier<MobileSettings> {
|
|||||||
_box?.put('showClock', value);
|
_box?.put('showClock', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toggleShowDebugStats(bool value) {
|
||||||
|
state = state.copyWith(showDebugStats: value);
|
||||||
|
_box?.put('showDebugStats', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDecoderMode(String mode) {
|
||||||
|
state = state.copyWith(decoderMode: mode);
|
||||||
|
_box?.put('decoderMode', mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPlayerEngine(String engine) {
|
||||||
|
state = state.copyWith(playerEngine: engine);
|
||||||
|
_box?.put('playerEngine', engine);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -63,3 +63,20 @@ final mobileSeriesInfoByPlaylistProvider = FutureProvider.family<SeriesInfo, Ser
|
|||||||
final service = await ref.watch(mobileXtreamServiceProvider(request.playlist).future);
|
final service = await ref.watch(mobileXtreamServiceProvider(request.playlist).future);
|
||||||
return service.getSeriesInfo(request.seriesId);
|
return service.getSeriesInfo(request.seriesId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// UI State Provider for persistent navigation
|
||||||
|
final mobileLiveTvUiStateProvider = StateProvider<LiveTvUiState>((ref) => LiveTvUiState());
|
||||||
|
|
||||||
|
class LiveTvUiState {
|
||||||
|
final String? selectedCategory;
|
||||||
|
final bool isCategoryView;
|
||||||
|
|
||||||
|
LiveTvUiState({this.selectedCategory, this.isCategoryView = true});
|
||||||
|
|
||||||
|
LiveTvUiState copyWith({String? selectedCategory, bool? isCategoryView}) {
|
||||||
|
return LiveTvUiState(
|
||||||
|
selectedCategory: selectedCategory ?? this.selectedCategory,
|
||||||
|
isCategoryView: isCategoryView ?? this.isCategoryView,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import '../../core/theme/app_colors.dart';
|
import '../../core/theme/app_colors.dart';
|
||||||
|
import 'tv_focusable.dart';
|
||||||
|
|
||||||
class MobileScaffold extends ConsumerWidget {
|
class MobileScaffold extends ConsumerWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
@@ -17,39 +18,72 @@ class MobileScaffold extends ConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
extendBody: true, // Allow content behind nav bar if transparent
|
|
||||||
backgroundColor: AppColors.background,
|
backgroundColor: AppColors.background,
|
||||||
body: child,
|
body: Column(
|
||||||
bottomNavigationBar: Container(
|
children: [
|
||||||
|
// Top Navigation Bar (TV Friendly)
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColors.surface,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.3),
|
||||||
|
blurRadius: 8,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: SafeArea(
|
||||||
|
bottom: false,
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
_buildNavItem(0, 'Live TV', Icons.tv),
|
||||||
|
_buildNavItem(1, 'Films', Icons.movie),
|
||||||
|
_buildNavItem(2, 'Séries', Icons.video_library),
|
||||||
|
_buildNavItem(3, 'Paramètres', Icons.settings),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Main Content
|
||||||
|
Expanded(child: child),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildNavItem(int index, String label, IconData icon) {
|
||||||
|
final isSelected = currentIndex == index;
|
||||||
|
return TVFocusable(
|
||||||
|
onPressed: () => onIndexChanged(index),
|
||||||
|
scale: 1.1,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border(top: BorderSide(color: AppColors.border.withOpacity(0.5), width: 0.5)),
|
color: isSelected ? AppColors.primary.withOpacity(0.15) : null,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: isSelected ? Border.all(color: AppColors.primary.withOpacity(0.5)) : null,
|
||||||
),
|
),
|
||||||
child: BottomNavigationBar(
|
child: Row(
|
||||||
currentIndex: currentIndex,
|
mainAxisSize: MainAxisSize.min,
|
||||||
onTap: onIndexChanged,
|
children: [
|
||||||
backgroundColor: AppColors.surface.withOpacity(0.95), // Highly opaque for readability
|
Icon(
|
||||||
type: BottomNavigationBarType.fixed,
|
icon,
|
||||||
showSelectedLabels: true,
|
color: isSelected ? AppColors.primary : AppColors.textSecondary,
|
||||||
showUnselectedLabels: true,
|
size: 20,
|
||||||
items: const [
|
|
||||||
BottomNavigationBarItem(
|
|
||||||
icon: Icon(Icons.tv),
|
|
||||||
label: 'Live',
|
|
||||||
),
|
),
|
||||||
BottomNavigationBarItem(
|
const SizedBox(width: 8),
|
||||||
icon: Icon(Icons.movie_outlined),
|
Text(
|
||||||
activeIcon: Icon(Icons.movie),
|
label,
|
||||||
label: 'Movies',
|
style: TextStyle(
|
||||||
),
|
color: isSelected ? AppColors.primary : AppColors.textSecondary,
|
||||||
BottomNavigationBarItem(
|
fontWeight: isSelected ? FontWeight.bold : FontWeight.w500,
|
||||||
icon: Icon(Icons.video_library_outlined),
|
fontSize: 14,
|
||||||
activeIcon: Icon(Icons.video_library),
|
),
|
||||||
label: 'Series',
|
|
||||||
),
|
|
||||||
BottomNavigationBarItem(
|
|
||||||
icon: Icon(Icons.settings_outlined),
|
|
||||||
activeIcon: Icon(Icons.settings),
|
|
||||||
label: 'Settings',
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import '../../../../core/theme/app_colors.dart';
|
||||||
|
|
||||||
|
class TVFocusable extends StatefulWidget {
|
||||||
|
final Widget child;
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
final VoidCallback? onFocus;
|
||||||
|
final FocusNode? focusNode;
|
||||||
|
final bool autofocus;
|
||||||
|
final double scale;
|
||||||
|
final double borderWidth;
|
||||||
|
final Color focusColor;
|
||||||
|
final BorderRadius? borderRadius;
|
||||||
|
|
||||||
|
const TVFocusable({
|
||||||
|
super.key,
|
||||||
|
required this.child,
|
||||||
|
this.onPressed,
|
||||||
|
this.onFocus,
|
||||||
|
this.focusNode,
|
||||||
|
this.autofocus = false,
|
||||||
|
this.scale = 1.05,
|
||||||
|
this.borderWidth = 3.0,
|
||||||
|
this.focusColor = Colors.white,
|
||||||
|
this.borderRadius,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<TVFocusable> createState() => _TVFocusableState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TVFocusableState extends State<TVFocusable> {
|
||||||
|
late FocusNode _node;
|
||||||
|
bool _isFocused = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_node = widget.focusNode ?? FocusNode();
|
||||||
|
_node.addListener(_onFocusChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
if (widget.focusNode == null) {
|
||||||
|
_node.dispose();
|
||||||
|
} else {
|
||||||
|
_node.removeListener(_onFocusChanged);
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onFocusChanged() {
|
||||||
|
if (_node.hasFocus != _isFocused) {
|
||||||
|
setState(() => _isFocused = _node.hasFocus);
|
||||||
|
if (_isFocused) {
|
||||||
|
widget.onFocus?.call();
|
||||||
|
_scrollToVisible();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _scrollToVisible() {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (!mounted) return;
|
||||||
|
Scrollable.ensureVisible(
|
||||||
|
context,
|
||||||
|
alignment: 0.5, // Center the item
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handlePress() {
|
||||||
|
widget.onPressed?.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Focus(
|
||||||
|
focusNode: _node,
|
||||||
|
autofocus: widget.autofocus,
|
||||||
|
onKeyEvent: (node, event) {
|
||||||
|
if (event is KeyDownEvent) {
|
||||||
|
final key = event.logicalKey;
|
||||||
|
if (key == LogicalKeyboardKey.select ||
|
||||||
|
key == LogicalKeyboardKey.enter ||
|
||||||
|
key == LogicalKeyboardKey.space ||
|
||||||
|
key == LogicalKeyboardKey.gameButtonA ||
|
||||||
|
key == LogicalKeyboardKey.numpadEnter) {
|
||||||
|
_handlePress();
|
||||||
|
return KeyEventResult.handled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return KeyEventResult.ignored;
|
||||||
|
},
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: _handlePress,
|
||||||
|
child: TweenAnimationBuilder<double>(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
tween: Tween<double>(
|
||||||
|
begin: 1.0,
|
||||||
|
end: _isFocused ? widget.scale : 1.0,
|
||||||
|
),
|
||||||
|
builder: (context, scale, child) {
|
||||||
|
return Transform.scale(
|
||||||
|
scale: scale,
|
||||||
|
child: Container(
|
||||||
|
foregroundDecoration: _isFocused
|
||||||
|
? BoxDecoration(
|
||||||
|
border: Border.all(
|
||||||
|
color: widget.focusColor,
|
||||||
|
width: widget.borderWidth,
|
||||||
|
),
|
||||||
|
borderRadius: widget.borderRadius ?? BorderRadius.circular(12),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: widget.child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,7 @@ dependencies:
|
|||||||
equatable: ^2.0.5
|
equatable: ^2.0.5
|
||||||
shared_preferences: ^2.3.2
|
shared_preferences: ^2.3.2
|
||||||
path_provider: ^2.1.5
|
path_provider: ^2.1.5
|
||||||
|
video_player: ^2.10.1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user