fluttercommunity / fluttercommunity/chewie
seekTo() and addListener()
- Dominant language
- Dart
- Stars
- 2.1k
- Forks
- 1.1k
- Avg merge
- 6d 8h
- Merged PRs (30d)
- 6
Description
With the most recent version of Chewie, I have been unable to implement a video block that starts a video at a specific time using` seekTo()`. Also I am unable to stop the video at a specific time using `addListener()`
With Chewie version 0.9.0 this code works correctly, however in the transition to the new version, I have not found a solution.
```dart
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
import 'package:screen/screen.dart';
class VideoBlock extends StatefulWidget {
int start, end;
File movie;
VideoBlock({Key key, @required this.movie, this.start, this.end})
: super(key: key);
@override
_VideoBlockState createState() => _VideoBlockState();
}
class _VideoBlockState extends State {
VideoPlayerController _controller;
VoidCallback _checkEnd;
@override
initState() {
super.initState();
print(this.widget.start.toString() + ' ' + this.widget.end.toString());
Screen.keepOn(true);
_controller = VideoPlayerController.file(this.widget.movie);
if (this.widget.start == null) this.widget.start = 0;
_checkEnd = () {
if (_controller.value.initialized) {
if (Duration(seconds: this.widget.end)
.compareTo(_controller.value.position) <
0) {
_controller.pause();
}
}
};
if (this.widget.end != null) _controller.addListener(_checkEnd);
}
@override
void dispose() {
Screen.keepOn(false);
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Chewie(
_controller,
startAt: Duration(seconds: this.widget.start),
aspectRatio: 16 / 9,
autoInitialize: true,
autoPlay: true,
looping: false,
);
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the provided VideoBlock with the current Chewie version and compare it with version 0.9.0. Start by tracing the VideoPlayerController usage around startAt, seekTo(), and addListener(), then verify that playback starts at the requested time and pauses at the requested end time.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100