我的英文不是很好,准备了一个IP看电视直播的应用程序,有广播,没有问题,我看广播,切换到另一个广播时,在没有来的广播上崩溃。
我想在这里写的代码中检查传入的发布,这样发布没有来的时候不报错,返回主页或者可以写在文章中,就好像这个发布不存在一样。谢谢
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),
),
],
),
),
),
),
],
),
);
}
}