Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
developer-zerobug opened this issue Apr 19, 2024 · 0 comments
Open

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

developer-zerobug opened this issue Apr 19, 2024 · 0 comments

Comments

@developer-zerobug
Copy link

developer-zerobug commented Apr 19, 2024

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 developer-zerobug changed the title I can't play running a live hls video in my app I can't play a live hls video in my app Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant