chewie icon indicating copy to clipboard operation
chewie copied to clipboard

Android: After 30 seconds of live streaming, the icon changes to "start over/restart", although the broadcast continues and the expected result is "pause".

Open ohlegs opened this issue 10 months ago • 1 comments

https://github.com/user-attachments/assets/326e31d1-8e90-4988-9366-a3cf94a8a675

Code example but not work in web: https://zapp.run/edit/flutter-zlkg06gqlkh0?entry=lib/main.dart&file=lib/main.dart:0-4178

OR

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


const primaryColor = Color(0xFF0C3955);
const backgroudColor = Color(0xFFEDF1F7);

class TranslationScreen extends StatefulWidget {
  final String name;
  final bool isLive;

  const TranslationScreen({
    super.key,
    required this.name,
    required this.isLive,
  });

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

class _TranslationScreenState extends State<TranslationScreen> {
  VideoPlayerController? _videoPlayerController;
  late ChewieController _chewieController;
  int? bufferDelay;
  bool _isError = false;
  final bool _isVideoFinished = false;

  @override
  void initState() {
    super.initState();
    initializePlayer('https://back.art-caramel.ru/stream/5debd92c-5247-4760-9bca-176290c2f4b8.m3u8');
  }

  @override
  void dispose() {
    _videoPlayerController?.dispose();
    _chewieController.dispose();
    super.dispose();
  }

  Uri _getUrl(String videoUrl) {
    return Uri.parse(videoUrl.trim());
  }

  Future<void> initializePlayer(String videoUrl) async {
    try {
      _videoPlayerController = VideoPlayerController.networkUrl(_getUrl(videoUrl));
      await _videoPlayerController!.initialize();
      _videoPlayerController!.addListener(checkVideo);
      _createChewieController();
      setState((){});
    } catch (e) {
      print(e);
      setState(() {
        _isError = true;
      });
    }
  }

  void _createChewieController() {
    if (_videoPlayerController != null) {
      _chewieController = ChewieController(
        isLive: widget.isLive,
        videoPlayerController: _videoPlayerController!,
        autoPlay: true,
        showControlsOnInitialize: false,
        deviceOrientationsAfterFullScreen: [
          DeviceOrientation.portraitUp,
          DeviceOrientation.portraitDown,
        ],
        aspectRatio: 16 / 9,
        looping: false,
        materialProgressColors: ChewieProgressColors(
          bufferedColor: Colors.grey,
          playedColor: primaryColor,
        ),
        cupertinoProgressColors: ChewieProgressColors(
          bufferedColor: Colors.grey,
          playedColor: primaryColor,
        ),
        controlsSafeAreaMinimum: const EdgeInsets.all(8),
        progressIndicatorDelay: bufferDelay != null ? Duration(milliseconds: bufferDelay!) : null,
        hideControlsTimer: const Duration(seconds: 5),
      );
      setState(() {}); // Trigger a rebuild to update the UI with the Chewie controller
    }
  }

  void checkVideo() {
    // if (_videoPlayerController1!.value.position ==
    //     Duration(seconds: 0, minutes: 0, hours: 0)) {
    //   print('video Started');
    // }

    // if (_videoPlayerController1!.value.isCompleted) {
    //   logger.d('video Ended');
    //   _chewieController!.pause();
    // }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: _isError ? backgroudColor : Colors.black,
      appBar: AppBar(
        foregroundColor: backgroudColor,
        leading: IconButton(
          icon: const Icon(
            Icons.arrow_back,
            color: primaryColor,
          ),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        elevation: 0,
        backgroundColor: backgroudColor,
        centerTitle: false,
        title: Text(widget.name),
      ),
      body: _videoPlayerController != null && _videoPlayerController!.value.isInitialized
          ? Chewie(controller: _chewieController)
          : const Center(child: CircularProgressIndicator()), // Show a loading indicator while initializing
    );
  }
}

ohlegs avatar Feb 12 '25 14:02 ohlegs

The link with the video stream : https://prod-back.art-caramel.ru/stream/813bf122-364d-41f0-b8ee-3f88ffde02b5.m3u8

ohlegs avatar Feb 12 '25 14:02 ohlegs