提交 566881a7 authored 作者: jungleiOS's avatar jungleiOS

添加长按2倍速播放

上级 bb8cbc95
......@@ -332,7 +332,6 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
// debugPrint("error: " + controller.value.errorDescription);
if (_controller.value.isPlaying) {
_controller.setPlaybackSpeed(_speedItem.speed);
setState(() {
if (oDuration.inHours == 0) {
var strPosition = oPosition.toString().split('.')[0];
......@@ -370,6 +369,9 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
_controller.play();
_isEnded = false;
}
Future.delayed(const Duration(seconds: 1), () {
_controller.setPlaybackSpeed(_speedItem.speed);
});
}
void _initPlayer() {
......@@ -426,9 +428,9 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
} else {
if (Platform.isIOS) {
GzOrientation.forceOrientation(DeviceOrientation.landscapeRight);
}
else {
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
} else {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft]);
}
}
}
......@@ -872,6 +874,25 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
},
onVerticalDragEnd: (DragEndDetails details) {},
/// 长按 2 倍速播放
onLongPress: () {
if (!_controller.value.isInitialized) return;
VideoSpeedItem item = VideoSpeedItem(speed: 2.0, title: '2X');
_controller.setPlaybackSpeed(item.speed);
widget.onSpeedChange?.call(item);
_speedTitle = item.title;
setState(() {});
},
/// 取消长按恢复之前选择的速度播放
onLongPressUp: () {
if (!_controller.value.isInitialized) return;
_controller.setPlaybackSpeed(_speedItem.speed);
widget.onSpeedChange?.call(_speedItem);
_speedTitle = _speedItem.title;
setState(() {});
},
///视频播放器
child: ClipRect(
child: Container(
......
......@@ -4,7 +4,7 @@ class VideoSpeedItem {
final double speed;
final String title;
VideoSpeedItem({this.speed = 1.0, this.title = '1.0X'});
VideoSpeedItem({this.speed = 1.0, this.title = '1X'});
}
class VideoSpeedItemStyle {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论