chewie icon indicating copy to clipboard operation
chewie copied to clipboard

How to check Player start playing video?

Open aipxperts-developer opened this issue 2 years ago • 1 comments

Hi, i need to call 1 api when user video playing starts and for that i add listener to check it but not working as expected. Below is my code.

@override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(
        widget.url)
      ..initialize().then((_) {
        setState(() {});
      });

    _controller!.addListener(checkVideo);
  }

void checkVideo() {
    // Implement your calls inside these conditions' bodies :
    if (_controller!.value.position ==
            const Duration(seconds: 0, minutes: 0, hours: 0) &&
        _controller!.value.isPlaying) {
      print('video Started');
    }

    if (!_controller!.value.isPlaying &&
        _controller!.value.isInitialized &&
        (_controller!.value.duration == _controller!.value.position)) {
      print('video Ended ${_controller!.value.duration}');
    }
  }

But this condition become true multiple times even if video doesn't play started and while buffering. if (_controller!.value.position == const Duration(seconds: 0, minutes: 0, hours: 0) && _controller!.value.isPlaying)

NOTE: This issue generate when i press press button without video buffers completely. (Works file it i press play button once video bufferes 100%) How to check Video start & Stop correctly?

aipxperts-developer avatar Dec 06 '21 13:12 aipxperts-developer

@aipxperts-developer did you find any solution to this?

Omi231 avatar Sep 14 '22 12:09 Omi231

@aipxperts-developer _controller!.value.isPlaying

monkeydaichan avatar Nov 22 '22 21:11 monkeydaichan