提交 3a78419c authored 作者: jungleiOS's avatar jungleiOS

处理 iOS seekTo 后导致播放速度被重置问题

上级 0d7e0527
......@@ -540,7 +540,7 @@ class _VideoPlayerPageState extends State<VideoPlayerPage> {
child: CustomBtn(
title: '播放到指定位置',
onTap: () {
state?.seekTo(const Duration(seconds: 10));
state?.seekTo(const Duration(seconds: 2));
},
),
),
......
......@@ -12,6 +12,23 @@ class _OtherTestPageState extends State<OtherTestPage> {
String url =
'https://mpv.videocc.net/8f38fa3352/c/8f38fa3352a8cc8f70dd384edb9b21dc_1.mp4';
late VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.networkUrl(Uri.parse(url));
_controller.initialize().then((value) {
_controller.play();
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -20,11 +37,43 @@ class _OtherTestPageState extends State<OtherTestPage> {
),
body: Column(
children: [
GZVideoPlayer(
dataSource: url,
sourceType: DataSourceType.network,
restoreVertical: false,
// GZVideoPlayer(
// dataSource: url,
// sourceType: DataSourceType.network,
// restoreVertical: false,
// ),
AspectRatio(
aspectRatio: 16 / 9,
child: VideoPlayer(_controller),
),
GestureDetector(
onTap: () {
_controller.setPlaybackSpeed(2.0);
},
behavior: HitTestBehavior.translucent,
child: Container(
width: 100,
height: 40,
color: Colors.black.withOpacity(0.5),
alignment: Alignment.center,
child: const Text('2倍速'),
),
),
GestureDetector(
onTap: () {
_controller.seekTo(const Duration(seconds: 22));
},
behavior: HitTestBehavior.translucent,
child: Container(
width: 100,
height: 40,
color: Colors.black.withOpacity(0.5),
alignment: Alignment.center,
child: const Text('sekTo'),
),
)
],
),
);
......
......@@ -85,10 +85,10 @@ packages:
dependency: "direct main"
description:
name: cupertino_icons
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
version: "1.0.6"
fake_async:
dependency: transitive
description:
......@@ -101,10 +101,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: ed5337a5660c506388a9f012be0288fb38b49020ce2b45fe1f8b8323fe429f99
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.2"
version: "2.1.0"
flutter:
dependency: "direct main"
description: flutter
......@@ -164,10 +164,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
version: "2.1.1"
matcher:
dependency: transitive
description:
......@@ -321,10 +321,10 @@ packages:
dependency: transitive
description:
name: video_player
sha256: d3910a8cefc0de8a432a4411dcf85030e885d8fef3ddea291f162253a05dbf01
sha256: "74b86e63529cf5885130c639d74cd2f9232e7c8a66cbecbddd1dcb9dbd060d1e"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.7.1"
version: "2.7.2"
video_player_android:
dependency: transitive
description:
......@@ -337,10 +337,10 @@ packages:
dependency: transitive
description:
name: video_player_avfoundation
sha256: c3b123a5a56c9812b9029f840c65b92fd65083eb08d69be016b01e8aa018f77d
sha256: bf1a1322bf68bccd349982ba1f5a41314a3880861fb9a93d25d6d0a2345845f0
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.10"
version: "2.4.11"
video_player_platform_interface:
dependency: transitive
description:
......
......@@ -420,7 +420,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
setState(() {});
if (widget.playOptions.autoplay) {
if (widget.playOptions.startPosition.inSeconds != 0) {
_controller.seekTo(widget.playOptions.startPosition);
seekTo(widget.playOptions.startPosition);
}
_controller.play();
_isEnded = false;
......@@ -443,10 +443,22 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
..setLooping(widget.playOptions.loop);
}
/// ios seekTo 会导致播发速度重置
/// 统一处理 seekTo 后1.5秒 重设播放速度
void seekTo(Duration position) {
if (_controller.value.isInitialized &&
position.inSeconds < _controller.value.duration.inSeconds) {
_controller.seekTo(position);
position.inSeconds <= _controller.value.duration.inSeconds &&
position.inSeconds >= 0) {
if (Platform.isIOS) {
_controller.seekTo(position);
Future.delayed(const Duration(milliseconds: 1500), () {
_controller.setPlaybackSpeed(_speedItem.speed);
debugPrint(
'-----> playbackSpeed = ${_controller.value.playbackSpeed}');
});
} else {
_controller.seekTo(position);
}
}
}
......@@ -542,7 +554,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
setState(() {
debugPrint(_controller.value.position.toString());
var currentPosition = _controller.value.position;
_controller.seekTo(Duration(
seekTo(Duration(
seconds: currentPosition.inSeconds - widget.playOptions.seekSeconds));
});
}
......@@ -553,7 +565,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
setState(() {
var currentPosition = _controller.value.position;
_controller.seekTo(Duration(
seekTo(Duration(
seconds: currentPosition.inSeconds + widget.playOptions.seekSeconds));
});
}
......@@ -639,6 +651,9 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
onDragEnd: () {
_estimatedTimeNotifier.dragEnd();
},
onSeekTo: (Duration position) {
seekTo(position);
},
padding:
widget.videoStyle.videoControlBarStyle.progressStyle.padding,
progressStyle: widget.videoStyle.videoControlBarStyle.progressStyle,
......@@ -850,7 +865,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
type: item.sourceType,
source: item.dataSource,
initializeCallback: () {
_controller.seekTo(position);
seekTo(position);
},
);
_isBuffing = true;
......@@ -931,7 +946,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
milliseconds = milliseconds < 0 ? 0 : milliseconds;
position = Duration(milliseconds: milliseconds);
}
_controller.seekTo(position);
seekTo(position);
_estimatedTimeNotifier.update(
position: position,
duration: _controller.value.duration,
......
......@@ -15,6 +15,7 @@ class VideoLinearProgressBar extends StatefulWidget {
this.padding = const EdgeInsets.only(top: 5.0),
this.onProgressDrag,
this.onDragEnd,
this.onSeekTo,
}) : progressStyle = progressStyle ?? VideoProgressStyle();
final VideoPlayerController controller;
......@@ -29,6 +30,8 @@ class VideoLinearProgressBar extends StatefulWidget {
final VoidCallback? onDragEnd;
final ValueChanged<Duration>? onSeekTo;
@override
State<StatefulWidget> createState() => _VideoLinearProgressBarState();
}
......@@ -64,6 +67,7 @@ class _VideoLinearProgressBarState extends State<VideoLinearProgressBar> {
controller: controller,
handleDrag: widget.onProgressDrag,
onDragEnd: widget.onDragEnd,
onSeekTo: widget.onSeekTo,
child: CustomPaint(
painter: _ProgressBarPainter(controller.value, style),
child: Container(),
......@@ -79,12 +83,14 @@ class _VideoScrubber extends StatefulWidget {
required this.controller,
this.handleDrag,
this.onDragEnd,
this.onSeekTo,
});
final Widget child;
final VideoPlayerController controller;
final VideoProgressDragHandle? handleDrag;
final VoidCallback? onDragEnd;
final ValueChanged<Duration>? onSeekTo;
@override
_VideoScrubberState createState() => _VideoScrubberState();
......@@ -102,7 +108,7 @@ class _VideoScrubberState extends State<_VideoScrubber> {
final Offset tapPos = box.globalToLocal(globalPosition);
final double relative = tapPos.dx / box.size.width;
final Duration position = controller.value.duration * relative;
controller.seekTo(position);
widget.onSeekTo?.call(position);
}
void emitDragUpdate(globalPosition) {
......
......@@ -11,7 +11,7 @@ dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.0.2
video_player: ^2.7.0
video_player: ^2.7.2
connectivity: ^3.0.6
screen_brightness: ^0.2.2+1
wakelock: ^0.6.2
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论