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

SetLooping is not working, and play makes StackOverflow #236

Open
com8599 opened this issue Apr 25, 2024 · 1 comment
Open

SetLooping is not working, and play makes StackOverflow #236

com8599 opened this issue Apr 25, 2024 · 1 comment

Comments

@com8599
Copy link

com8599 commented Apr 25, 2024

env

ffmpeg_kit_flutter: ^6.0.3
flutter_video_info: ^1.3.2
video_trimmer: ^3.0.1

I want to seek to _startValue and play when end dragging rightcircle, but when I drag rightcircle, it play at _endValue and not looping.
And I make this code.
But, the code makes stackoverflow.

TrimViewer(
  trimmer: trimmer,
  viewerHeight: 56.0,
  viewerWidth: MediaQuery.of(context).size.width,
  maxVideoLength: const Duration(seconds: 30),
  onChangeStart: (value) => _startValue = value,
  onChangeEnd: (value) => _endValue = value,
  onChangePlaybackState: (value) => setState(() {
    _isPlaying = value;
    if (!_isPlaying) {
      trimmer.videoPlayerController
          ?.seekTo(Duration(seconds: _startValue.toInt()));
      // trimmer.videoPlayerController?.play(); <= it makes stackoverflow
    }
  }),
),

stackoverflow message

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Stack Overflow
#0      _StringBase._interpolate (dart:core-patch/string_patch.dart:857:3)
#1      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:439:87)
#2      VideoPlayerController.play (package:video_player/video_player.dart:533:5)
#3      _MediaPreviewState.build.<anonymous closure>.<anonymous closure> (package:kizling_flutter/page/kizling/media_select.new.dart:208:48)
#4      State.setState (package:flutter/src/widgets/framework.dart:1203:30)
#5      _MediaPreviewState.build.<anonymous closure> (package:myproject/page/mine/media_select.new.dart:203:47)
#6      _FixedTrimViewerState._initializeVideoController.<anonymous closure> (package:video_trimmer/src/trim_viewer/fixed_viewer/fixed_trim_viewer.dart:293:44)
#7      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:433:24)
#8      VideoPlayerController.pause (package:video_player/video_player.da<…>

I think that there are infinite loop in TrimViewer,
Can you fix this problem?

@com8599
Copy link
Author

com8599 commented Apr 25, 2024

I found out a solution

  void _onDragUpdate(DragUpdateDetails details) {
    if (!_allowDrag) return;

    if (_dragType == EditorDragType.left) {
      _startCircleSize = widget.editorProperties.circleSizeOnDrag;
      if ((_startPos.dx + details.delta.dx >= 0) &&
          (_startPos.dx + details.delta.dx <= _endPos.dx) &&
          !(_endPos.dx - _startPos.dx - details.delta.dx > maxLengthPixels!)) {
        _startPos += details.delta;
        _onStartDragged();
      }
    } else if (_dragType == EditorDragType.center) {
      _startCircleSize = widget.editorProperties.circleSizeOnDrag;
      _endCircleSize = widget.editorProperties.circleSizeOnDrag;
      if ((_startPos.dx + details.delta.dx >= 0) &&
          (_endPos.dx + details.delta.dx <= _thumbnailViewerW)) {
        _startPos += details.delta;
        _endPos += details.delta;
        _onStartDragged();
        _onEndDragged();
      }
    } else {
      _endCircleSize = widget.editorProperties.circleSizeOnDrag;
      if ((_endPos.dx + details.delta.dx <= _thumbnailViewerW) &&
          (_endPos.dx + details.delta.dx >= _startPos.dx) &&
          !(_endPos.dx - _startPos.dx + details.delta.dx > maxLengthPixels!)) {
        _endPos += details.delta;
        _onStartDragged(); <- my code
        _onEndDragged();
      }
    }
    setState(() {});
  }
...
/// Drag gesture ended, update UI accordingly.
void _onDragEnd(DragEndDetails details) {
  setState(() {
    _startCircleSize = widget.editorProperties.circleSize;
    _endCircleSize = widget.editorProperties.circleSize;
    if (_dragType == EditorDragType.right) {
      videoPlayerController
          .seekTo(Duration(milliseconds: _videoStartPos.toInt())); <- my code
         //  .seekTo(Duration(milliseconds: _videoEndPos.toInt())); <- pure code
    } else {
      videoPlayerController
          .seekTo(Duration(milliseconds: _videoStartPos.toInt()));
    }
  });
}

please fix the line

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