import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Video Stream Demo',
home: VideoStreamPlayer(),
);
}
}
class VideoStreamPlayer extends StatefulWidget {
const VideoStreamPlayer({super.key});
@override
_VideoStreamPlayerState createState() => _VideoStreamPlayerState();
}
class _VideoStreamPlayerState extends State<VideoStreamPlayer> {
VideoPlayerController? _controller;
ChewieController? chewieController;
Chewie? playerWidget;
bool load = false;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://live1.panet.co.il/edge_abr/halaTV/playlist.m3u8');
// chewieController = ChewieController(
// videoPlayerController: _controller!,
// autoPlay: true,
// looping: true,
// );
_controller!.setLooping(true);
_controller!.initialize().then((_) {
setState(() {
load = true;
});
_controller!.play();
});
}
@override
Widget build(BuildContext context) {
if (_controller!.value.isInitialized) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Stack(
children: [
// if (load) Chewie(controller: chewieController!),
AspectRatio(
aspectRatio: 16 / 9,
child: VideoPlayer(_controller!),
),
Container(
margin: const EdgeInsets.only(top: 5, right: 5, left: 5),
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(13)),
child: const Text(
'live',
style: TextStyle(fontSize: 27, color: Colors.white),
))
],
),
),
);
} else {
return const Center(child: CircularProgressIndicator());
}
}
@override
void dispose() {
super.dispose();
_controller!.dispose();
chewieController!.dispose();
}
}