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

Video position stuck at 15 seconds #501

Open
JasperElton opened this issue Aug 21, 2024 · 0 comments
Open

Video position stuck at 15 seconds #501

JasperElton opened this issue Aug 21, 2024 · 0 comments

Comments

@JasperElton
Copy link

It seems like the position is stuck at 15 seconds and do not fully end the length of the video as I printed the video duration(20 seconds) and whenever the slide thumb reaches 15.25 seconds it stuck's. Also here is my code:

class SlideVideoSlider extends StatefulWidget {
  final VlcPlayerController? vlcPlayerController;
  final AudioPlayer? audioPlayer;
  final VoidCallback? onChanged;

  const SlideVideoSlider({
    super.key,
    required this.vlcPlayerController,
    required this.audioPlayer,
    this.onChanged,
  });

  @override
  State<SlideVideoSlider> createState() => _SlideVideoSliderState();
}

class _SlideVideoSliderState extends State<SlideVideoSlider> {
  var duration = Duration.zero;
  var position = Duration.zero;

  @override
  void initState() {
    super.initState();
    widget.vlcPlayerController!.addListener(_onPlayerControllerUpdated);
  }

  @override
  void dispose() {
    widget.vlcPlayerController!.removeListener(_onPlayerControllerUpdated);
    super.dispose();
  }

  Future<void> _onPlayerControllerUpdated() async {
    if (mounted) {
      setState(() {
        duration = widget.vlcPlayerController?.value.duration ?? Duration.zero;
        position = widget.vlcPlayerController?.value.position ?? Duration.zero;
        debugPrint('here Duration: $duration, Position: $position');
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return SliderTheme(
      data: const SliderThemeData(
        thumbShape: RoundSliderThumbShape(enabledThumbRadius: 8),
      ),
      child: Slider(
        value: (position.inMilliseconds / duration.inMilliseconds).isNaN
            ? 0
            : position.inMilliseconds / duration.inMilliseconds,
        onChanged: (value) {
          setState(() {
            final seekSeconds =
                (value * duration.inMilliseconds.toDouble()).toInt();
            position = Duration(seconds: seekSeconds);
            widget.vlcPlayerController?.seekTo(position);

            if (widget.audioPlayer != null) {
              widget.audioPlayer?.seek(position);
              widget.audioPlayer?.resume();
            }
            widget.vlcPlayerController?.play();
            widget.onChanged!();
          });
        },
      ),
    );
  }
}
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