import 'dart:async';
import 'package:flutter/material.dart';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
class ChapterDetailsPage extends StatefulWidget {
const ChapterDetailsPage({super.key});
@override
State<ChapterDetailsPage> createState() => _ChapterDetailsPageState();
}
class _ChapterDetailsPageState extends State<ChapterDetailsPage> {
late VideoPlayerController _videoPlayerController;
ChewieController? _chewieController;
Timer? _timer;
bool _isPlaying = false; // Define _isPlaying
@override
void initState() {
super.initState();
initializePlayer();
}
Future<void> initializePlayer() async {
_videoPlayerController = VideoPlayerController.networkUrl(Uri.parse(
'https://res.cloudinary.com/dnebaumu9/video/upload/v1739640566/public_videos/wq9wkj9qvr8d3sysqrmm.mp4'));
await _videoPlayerController.initialize();
_videoPlayerController.addListener(() {
final bool isPlaying = _videoPlayerController.value.isPlaying;
if (isPlaying != _isPlaying) {
print("Video is ${isPlaying ? 'playing' : 'paused'}");
setState(() {
_isPlaying = isPlaying;
});
}
print('Current position: ${_videoPlayerController.value.position}');
setState(() {});
});
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
autoPlay: true,
looping: true,
allowFullScreen: true,
showControls: true,
materialProgressColors: ChewieProgressColors(
playedColor: Colors.blue,
handleColor: Colors.blueAccent,
backgroundColor: Colors.grey,
),
);
startTimer();
setState(() {});
}
void startTimer() {
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
if (_videoPlayerController.value.isInitialized &&
_videoPlayerController.value.isPlaying) {
print(
'Timer update - Current position: ${_videoPlayerController.value.position}');
setState(() {});
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Chapter Details')),
body: LayoutBuilder(
builder: (context, constraints) {
if (_chewieController != null &&
_chewieController!.videoPlayerController.value.isInitialized) {
return Chewie(controller: _chewieController!);
} else {
return Center(child: CircularProgressIndicator());
}
},
),
);
}
@override
void dispose() {
_timer?.cancel();
_videoPlayerController.dispose();
_chewieController?.dispose();
super.dispose();
}
}
Here is my code and why are not the chewie controllers being updated as the video keeps playing the controllers are stuck with the current position / remaining time and progress bar help me fix this issue please
I have been trying to fetch the video in my Flutter app with the url and the video is being playing but the current time , remaining time and the progress bars are not being updated and is stucked as the video keeps on playing
Troubleshooting
I have tried every possible approach as my link is also fully verified that when i try to play the video through the url too its gets played showing the progress bar current position being auto updated but when it comes to flutter just the video gets playes other everything gets stuck
Yes
1