171 lines
5.6 KiB
Dart
171 lines
5.6 KiB
Dart
import 'package:chewie/chewie.dart';
|
|
import 'package:didvan/config/design_config.dart';
|
|
import 'package:didvan/models/didvan_plus_model.dart';
|
|
import 'package:didvan/services/network/request.dart';
|
|
import 'package:didvan/services/network/request_helper.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:didvan/views/widgets/video/primary_controls.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
class DidvanPlusVideoPlayer extends StatefulWidget {
|
|
final DidvanPlusModel video;
|
|
|
|
const DidvanPlusVideoPlayer({super.key, required this.video});
|
|
|
|
@override
|
|
State<DidvanPlusVideoPlayer> createState() => _DidvanPlusVideoPlayerState();
|
|
}
|
|
|
|
class _DidvanPlusVideoPlayerState extends State<DidvanPlusVideoPlayer> {
|
|
late VideoPlayerController _videoController;
|
|
ChewieController? _chewieController;
|
|
bool _isInitialized = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_initializeVideo();
|
|
}
|
|
|
|
void _initializeVideo() {
|
|
final videoUrl = '${RequestHelper.baseUrl}${widget.video.file}';
|
|
final fullUrl = '$videoUrl?accessToken=${RequestService.token}';
|
|
|
|
debugPrint('🎥 Video URL: $fullUrl');
|
|
|
|
_videoController = VideoPlayerController.networkUrl(
|
|
Uri.parse(fullUrl),
|
|
httpHeaders: {
|
|
'Authorization': 'Bearer ${RequestService.token}',
|
|
},
|
|
)..initialize().then((_) {
|
|
debugPrint('✅ Video initialized successfully');
|
|
setState(() {
|
|
_chewieController = ChewieController(
|
|
videoPlayerController: _videoController,
|
|
autoPlay: true,
|
|
looping: false,
|
|
allowFullScreen: true,
|
|
allowMuting: true,
|
|
showControls: true,
|
|
customControls: const PrimaryControls(),
|
|
materialProgressColors: ChewieProgressColors(
|
|
playedColor: DesignConfig.isDark
|
|
? const Color.fromARGB(255, 0, 125, 166)
|
|
: const Color.fromARGB(255, 0, 89, 119),
|
|
handleColor: DesignConfig.isDark
|
|
? const Color.fromARGB(255, 0, 125, 166)
|
|
: const Color.fromARGB(255, 0, 89, 119),
|
|
backgroundColor: Colors.grey,
|
|
bufferedColor: Colors.grey.shade300,
|
|
),
|
|
placeholder: Container(
|
|
color: Colors.black,
|
|
child: Center(
|
|
child: Image.network(
|
|
'${RequestHelper.baseUrl}${widget.video.image}',
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
_isInitialized = true;
|
|
});
|
|
}).catchError((error) {
|
|
debugPrint('❌ Video initialization error: $error');
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_videoController.dispose();
|
|
_chewieController?.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: true,
|
|
backgroundColor: Colors.black,
|
|
body: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
color: Colors.black,
|
|
child: Row(
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.close, color: Colors.white),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
),
|
|
Expanded(
|
|
child: Text(
|
|
widget.video.title,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Center(
|
|
child: _isInitialized && _chewieController != null
|
|
? Chewie(controller: _chewieController!)
|
|
: Container(
|
|
color: Colors.black,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
Image.network(
|
|
'${RequestHelper.baseUrl}${widget.video.image}',
|
|
fit: BoxFit.cover,
|
|
),
|
|
const Center(
|
|
child: CircularProgressIndicator(
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(16),
|
|
color:
|
|
DesignConfig.isDark ? const Color(0xFF1E1E1E) : Colors.white,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
DidvanText(
|
|
widget.video.title,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
const SizedBox(height: 8),
|
|
DidvanText(
|
|
widget.video.description,
|
|
fontSize: 14,
|
|
color: Colors.grey,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|