chewie icon indicating copy to clipboard operation
chewie copied to clipboard

I can't play a live hls video in my app

Open developer-zerobug opened this issue 1 year ago • 1 comments

I am facing a issue while running a Live HLS Video in my app here is a code for this:

It easily run recorded HLS video but no Live... Any solution for this...

`import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';`

`class Stream1 extends StatefulWidget {
  final String videoUrl;
  final String name;
  const Stream1({Key? key, required this.videoUrl, required this.name})
      : super(key: key);`

  
@override
  State<StatefulWidget> createState() {
    return _Stream1State();
  }
}



class _Stream1State extends State<Stream1> {
  TargetPlatform? _platform;
  late VideoPlayerController _videoPlayerController1;
  ChewieController? _chewieController1;

  @override
  void initState() {
    super.initState();
    initializePlayer();
  }

  @override
  void dispose() {
    _videoPlayerController1.dispose();
    _chewieController1?.dispose();
    super.dispose();
  }

  Future<void> initializePlayer() async {
    _videoPlayerController1 = VideoPlayerController.networkUrl(
        Uri.parse(widget.videoUrl),
        videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true));

    await _videoPlayerController1.initialize();
    _createChewieController();
    setState(() {});
  }

  void _createChewieController() {
    _chewieController1 = ChewieController(
      videoPlayerController: _videoPlayerController1,
      autoPlay: true,
      looping: true,
      customControls: Column(
        children: <Widget>[
          Align(
            alignment: Alignment.bottomLeft,
            child: Padding(
              padding: const EdgeInsets.fromLTRB(8.0, 24.0, 8.0, 8.0),
              child: Container(
                padding: EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 4.0),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8.0), // Set border radius
                  color: Colors.black.withOpacity(
                      0.5), 
                ),
                child: Text(
                  '${widget.name}',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 12,
                    // fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
          ),
          LinearProgressIndicator(
            value: 0.0, // Hide the progress bar
            valueColor: AlwaysStoppedAnimation<Color>(
                Colors.transparent), 
            backgroundColor:
                Colors.transparent, 
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: AppTheme.light.copyWith(
        platform: _platform ?? Theme.of(context).platform,
      ),
      home: Scaffold(
        body: Center(
            child: Padding(
          padding: const EdgeInsets.all(4.0),
          child: _chewieController1 != null &&
                  _chewieController1!.videoPlayerController.value.isInitialized
              ? Chewie(
                  controller: _chewieController1!,
                )
              : CircularProgressIndicator(),
        )),
      ),
    );
  }
}
`

developer-zerobug avatar Apr 19 '24 12:04 developer-zerobug

I encountered a similar issue, and I was wondering if you've found a solution yet?

hindevth avatar Sep 09 '24 08:09 hindevth