Reputation: 37
My English is not very good, I have prepared an application to watch TV broadcasts with IP, broadcasts are coming, there is no problem, I watch the broadcast, when I switch to another broadcast, it crashes on the broadcast that does not come.
I want to check the incoming publication in the code written here, so that it does not give an error when the publication does not come, it returns to the main page or it can be written in the article as if this publication does not exist. Thanks
class ChewieVideo extends GetxController {
final String videoData;
ChewieVideo({required this.videoData});
late VideoPlayerController videoPlayerController;
ChewieController? chewieController;
@override
void onClose() {
super.onClose();
videoPlayerController.dispose();
chewieController!.dispose();
}
@override
void onInit() {
super.onInit();
initializePlayer();
}
Future<void> initializePlayer() async {
videoPlayerController = VideoPlayerController.network(videoData);
await Future.wait([videoPlayerController.initialize()]);
chewieController = (ChewieController(
videoPlayerController: videoPlayerController,
autoPlay: true,
looping: true,
materialProgressColors: ChewieProgressColors(
playedColor: Colors.red,
handleColor: Colors.cyanAccent,
backgroundColor: Colors.yellow,
bufferedColor: Colors.lightGreen,
),
placeholder: Container(
color: Colors.white,
),
autoInitialize: true,
errorBuilder: (context, errorMessage) {
return Center(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
errorMessage,
style: TextStyle(color: white),
),
),
);
}));
update();
}
}
class VideoApp extends StatefulWidget {
const VideoApp(
{Key? key, required this.videoData, required this.channelLoading})
: super(key: key);
final String videoData;
final String channelLoading;
@override
State<VideoApp> createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
GetBuilder<ChewieVideo>(
init: ChewieVideo(videoData: widget.videoData),
builder: (controller) => Expanded(
child: Center(
child: controller.chewieController != null &&
controller.chewieController!.videoPlayerController.value
.isInitialized
? Chewie(controller: controller.chewieController!)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 10),
Text(
'${widget.channelLoading}=> Yükleniyor',
style: TextStyle(fontSize: 20),
),
],
),
),
),
),
],
),
);
}
}
Upvotes: 1
Views: 139