Skip to content

Commit

Permalink
fixed Checking end of a video play
Browse files Browse the repository at this point in the history
  • Loading branch information
brownsoo committed Oct 29, 2024
1 parent b753c3f commit 2b53a46
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/play_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,6 @@ class _PlayPageState extends State<PlayPage> {

void _onControllerUpdated() async {
if (_disposed) return;
// blocking too many updation
// important !!
final now = DateTime.now().millisecondsSinceEpoch;
if (_updateProgressInterval > now) {
return;
}
_updateProgressInterval = now + 500.0;

final controller = _controller;
if (controller == null) return;
if (!controller.value.isInitialized) return;
Expand All @@ -177,16 +169,28 @@ class _PlayPageState extends State<PlayPage> {
var position = await controller.position;
_position = position;
if (position == null) return;

// blocking too many updation
// important !!
final now = DateTime.now().millisecondsSinceEpoch;
if (_updateProgressInterval > now) {
// check if end of clip in update interval
if (!controller.value.isCompleted) {
return;
}
debugPrint("종료구만..");
}
_updateProgressInterval = now + 500.0;

final playing = controller.value.isPlaying;
final isEndOfClip =
controller.value.isCompleted || position.inMilliseconds > 0 && position.inSeconds + 1 >= duration.inSeconds;
if (playing) {
// handle progress indicator
if (_disposed) return;
setState(() {
_progress = position.inMilliseconds.ceilToDouble() / duration.inMilliseconds.ceilToDouble();
});
}
final isEndOfClip = controller.value.isCompleted;

// handle clip end
if (_isPlaying != playing || _isEndOfClip != isEndOfClip) {
Expand Down

0 comments on commit 2b53a46

Please sign in to comment.