Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
gz_video_player
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
蒋俊
gz_video_player
Commits
3a78419c
提交
3a78419c
authored
10月 18, 2023
作者:
jungleiOS
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
处理 iOS seekTo 后导致播放速度被重置问题
上级
0d7e0527
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
93 行增加
和
23 行删除
+93
-23
main.dart
example/lib/main.dart
+1
-1
other_test_page.dart
example/lib/other_test_page.dart
+53
-4
pubspec.lock
example/pubspec.lock
+10
-10
video.dart
lib/video.dart
+21
-6
linear_progress_bar.dart
lib/widget/linear_progress_bar.dart
+7
-1
pubspec.yaml
pubspec.yaml
+1
-1
没有找到文件。
example/lib/main.dart
浏览文件 @
3a78419c
...
@@ -540,7 +540,7 @@ class _VideoPlayerPageState extends State<VideoPlayerPage> {
...
@@ -540,7 +540,7 @@ class _VideoPlayerPageState extends State<VideoPlayerPage> {
child:
CustomBtn
(
child:
CustomBtn
(
title:
'播放到指定位置'
,
title:
'播放到指定位置'
,
onTap:
()
{
onTap:
()
{
state
?.
seekTo
(
const
Duration
(
seconds:
10
));
state
?.
seekTo
(
const
Duration
(
seconds:
2
));
},
},
),
),
),
),
...
...
example/lib/other_test_page.dart
浏览文件 @
3a78419c
...
@@ -12,6 +12,23 @@ class _OtherTestPageState extends State<OtherTestPage> {
...
@@ -12,6 +12,23 @@ class _OtherTestPageState extends State<OtherTestPage> {
String
url
=
String
url
=
'https://mpv.videocc.net/8f38fa3352/c/8f38fa3352a8cc8f70dd384edb9b21dc_1.mp4'
;
'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
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
...
@@ -20,11 +37,43 @@ class _OtherTestPageState extends State<OtherTestPage> {
...
@@ -20,11 +37,43 @@ class _OtherTestPageState extends State<OtherTestPage> {
),
),
body:
Column
(
body:
Column
(
children:
[
children:
[
GZVideoPlayer
(
// GZVideoPlayer(
dataSource:
url
,
// dataSource: url,
sourceType:
DataSourceType
.
network
,
// sourceType: DataSourceType.network,
restoreVertical:
false
,
// 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'
),
),
),
)
],
],
),
),
);
);
...
...
example/pubspec.lock
浏览文件 @
3a78419c
...
@@ -85,10 +85,10 @@ packages:
...
@@ -85,10 +85,10 @@ packages:
dependency: "direct main"
dependency: "direct main"
description:
description:
name: cupertino_icons
name: cupertino_icons
sha256:
e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
sha256:
d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "1.0.
5
"
version: "1.0.
6
"
fake_async:
fake_async:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -101,10 +101,10 @@ packages:
...
@@ -101,10 +101,10 @@ packages:
dependency: transitive
dependency: transitive
description:
description:
name: ffi
name: ffi
sha256:
ed5337a5660c506388a9f012be0288fb38b49020ce2b45fe1f8b8323fe429f99
sha256:
"7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "2.
0.2
"
version: "2.
1.0
"
flutter:
flutter:
dependency: "direct main"
dependency: "direct main"
description: flutter
description: flutter
...
@@ -164,10 +164,10 @@ packages:
...
@@ -164,10 +164,10 @@ packages:
dependency: transitive
dependency: transitive
description:
description:
name: lints
name: lints
sha256: "
5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593
"
sha256: "
0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452
"
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "2.
0
.1"
version: "2.
1
.1"
matcher:
matcher:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -321,10 +321,10 @@ packages:
...
@@ -321,10 +321,10 @@ packages:
dependency: transitive
dependency: transitive
description:
description:
name: video_player
name: video_player
sha256:
d3910a8cefc0de8a432a4411dcf85030e885d8fef3ddea291f162253a05dbf01
sha256:
"74b86e63529cf5885130c639d74cd2f9232e7c8a66cbecbddd1dcb9dbd060d1e"
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "2.7.
1
"
version: "2.7.
2
"
video_player_android:
video_player_android:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -337,10 +337,10 @@ packages:
...
@@ -337,10 +337,10 @@ packages:
dependency: transitive
dependency: transitive
description:
description:
name: video_player_avfoundation
name: video_player_avfoundation
sha256:
c3b123a5a56c9812b9029f840c65b92fd65083eb08d69be016b01e8aa018f77d
sha256:
bf1a1322bf68bccd349982ba1f5a41314a3880861fb9a93d25d6d0a2345845f0
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "2.4.1
0
"
version: "2.4.1
1
"
video_player_platform_interface:
video_player_platform_interface:
dependency: transitive
dependency: transitive
description:
description:
...
...
lib/video.dart
浏览文件 @
3a78419c
...
@@ -420,7 +420,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
...
@@ -420,7 +420,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
setState
(()
{});
setState
(()
{});
if
(
widget
.
playOptions
.
autoplay
)
{
if
(
widget
.
playOptions
.
autoplay
)
{
if
(
widget
.
playOptions
.
startPosition
.
inSeconds
!=
0
)
{
if
(
widget
.
playOptions
.
startPosition
.
inSeconds
!=
0
)
{
_controller
.
seekTo
(
widget
.
playOptions
.
startPosition
);
seekTo
(
widget
.
playOptions
.
startPosition
);
}
}
_controller
.
play
();
_controller
.
play
();
_isEnded
=
false
;
_isEnded
=
false
;
...
@@ -443,12 +443,24 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
...
@@ -443,12 +443,24 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
..
setLooping
(
widget
.
playOptions
.
loop
);
..
setLooping
(
widget
.
playOptions
.
loop
);
}
}
/// ios seekTo 会导致播发速度重置
/// 统一处理 seekTo 后1.5秒 重设播放速度
void
seekTo
(
Duration
position
)
{
void
seekTo
(
Duration
position
)
{
if
(
_controller
.
value
.
isInitialized
&&
if
(
_controller
.
value
.
isInitialized
&&
position
.
inSeconds
<
_controller
.
value
.
duration
.
inSeconds
)
{
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
);
_controller
.
seekTo
(
position
);
}
}
}
}
}
void
setVolume
(
double
volume
)
{
void
setVolume
(
double
volume
)
{
double
vol
=
volume
;
double
vol
=
volume
;
...
@@ -542,7 +554,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
...
@@ -542,7 +554,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
setState
(()
{
setState
(()
{
debugPrint
(
_controller
.
value
.
position
.
toString
());
debugPrint
(
_controller
.
value
.
position
.
toString
());
var
currentPosition
=
_controller
.
value
.
position
;
var
currentPosition
=
_controller
.
value
.
position
;
_controller
.
seekTo
(
Duration
(
seekTo
(
Duration
(
seconds:
currentPosition
.
inSeconds
-
widget
.
playOptions
.
seekSeconds
));
seconds:
currentPosition
.
inSeconds
-
widget
.
playOptions
.
seekSeconds
));
});
});
}
}
...
@@ -553,7 +565,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
...
@@ -553,7 +565,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
setState
(()
{
setState
(()
{
var
currentPosition
=
_controller
.
value
.
position
;
var
currentPosition
=
_controller
.
value
.
position
;
_controller
.
seekTo
(
Duration
(
seekTo
(
Duration
(
seconds:
currentPosition
.
inSeconds
+
widget
.
playOptions
.
seekSeconds
));
seconds:
currentPosition
.
inSeconds
+
widget
.
playOptions
.
seekSeconds
));
});
});
}
}
...
@@ -639,6 +651,9 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
...
@@ -639,6 +651,9 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
onDragEnd:
()
{
onDragEnd:
()
{
_estimatedTimeNotifier
.
dragEnd
();
_estimatedTimeNotifier
.
dragEnd
();
},
},
onSeekTo:
(
Duration
position
)
{
seekTo
(
position
);
},
padding:
padding:
widget
.
videoStyle
.
videoControlBarStyle
.
progressStyle
.
padding
,
widget
.
videoStyle
.
videoControlBarStyle
.
progressStyle
.
padding
,
progressStyle:
widget
.
videoStyle
.
videoControlBarStyle
.
progressStyle
,
progressStyle:
widget
.
videoStyle
.
videoControlBarStyle
.
progressStyle
,
...
@@ -850,7 +865,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
...
@@ -850,7 +865,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
type:
item
.
sourceType
,
type:
item
.
sourceType
,
source
:
item
.
dataSource
,
source
:
item
.
dataSource
,
initializeCallback:
()
{
initializeCallback:
()
{
_controller
.
seekTo
(
position
);
seekTo
(
position
);
},
},
);
);
_isBuffing
=
true
;
_isBuffing
=
true
;
...
@@ -931,7 +946,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
...
@@ -931,7 +946,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
milliseconds
=
milliseconds
<
0
?
0
:
milliseconds
;
milliseconds
=
milliseconds
<
0
?
0
:
milliseconds
;
position
=
Duration
(
milliseconds:
milliseconds
);
position
=
Duration
(
milliseconds:
milliseconds
);
}
}
_controller
.
seekTo
(
position
);
seekTo
(
position
);
_estimatedTimeNotifier
.
update
(
_estimatedTimeNotifier
.
update
(
position:
position
,
position:
position
,
duration:
_controller
.
value
.
duration
,
duration:
_controller
.
value
.
duration
,
...
...
lib/widget/linear_progress_bar.dart
浏览文件 @
3a78419c
...
@@ -15,6 +15,7 @@ class VideoLinearProgressBar extends StatefulWidget {
...
@@ -15,6 +15,7 @@ class VideoLinearProgressBar extends StatefulWidget {
this
.
padding
=
const
EdgeInsets
.
only
(
top:
5.0
),
this
.
padding
=
const
EdgeInsets
.
only
(
top:
5.0
),
this
.
onProgressDrag
,
this
.
onProgressDrag
,
this
.
onDragEnd
,
this
.
onDragEnd
,
this
.
onSeekTo
,
})
:
progressStyle
=
progressStyle
??
VideoProgressStyle
();
})
:
progressStyle
=
progressStyle
??
VideoProgressStyle
();
final
VideoPlayerController
controller
;
final
VideoPlayerController
controller
;
...
@@ -29,6 +30,8 @@ class VideoLinearProgressBar extends StatefulWidget {
...
@@ -29,6 +30,8 @@ class VideoLinearProgressBar extends StatefulWidget {
final
VoidCallback
?
onDragEnd
;
final
VoidCallback
?
onDragEnd
;
final
ValueChanged
<
Duration
>?
onSeekTo
;
@override
@override
State
<
StatefulWidget
>
createState
()
=>
_VideoLinearProgressBarState
();
State
<
StatefulWidget
>
createState
()
=>
_VideoLinearProgressBarState
();
}
}
...
@@ -64,6 +67,7 @@ class _VideoLinearProgressBarState extends State<VideoLinearProgressBar> {
...
@@ -64,6 +67,7 @@ class _VideoLinearProgressBarState extends State<VideoLinearProgressBar> {
controller:
controller
,
controller:
controller
,
handleDrag:
widget
.
onProgressDrag
,
handleDrag:
widget
.
onProgressDrag
,
onDragEnd:
widget
.
onDragEnd
,
onDragEnd:
widget
.
onDragEnd
,
onSeekTo:
widget
.
onSeekTo
,
child:
CustomPaint
(
child:
CustomPaint
(
painter:
_ProgressBarPainter
(
controller
.
value
,
style
),
painter:
_ProgressBarPainter
(
controller
.
value
,
style
),
child:
Container
(),
child:
Container
(),
...
@@ -79,12 +83,14 @@ class _VideoScrubber extends StatefulWidget {
...
@@ -79,12 +83,14 @@ class _VideoScrubber extends StatefulWidget {
required
this
.
controller
,
required
this
.
controller
,
this
.
handleDrag
,
this
.
handleDrag
,
this
.
onDragEnd
,
this
.
onDragEnd
,
this
.
onSeekTo
,
});
});
final
Widget
child
;
final
Widget
child
;
final
VideoPlayerController
controller
;
final
VideoPlayerController
controller
;
final
VideoProgressDragHandle
?
handleDrag
;
final
VideoProgressDragHandle
?
handleDrag
;
final
VoidCallback
?
onDragEnd
;
final
VoidCallback
?
onDragEnd
;
final
ValueChanged
<
Duration
>?
onSeekTo
;
@override
@override
_VideoScrubberState
createState
()
=>
_VideoScrubberState
();
_VideoScrubberState
createState
()
=>
_VideoScrubberState
();
...
@@ -102,7 +108,7 @@ class _VideoScrubberState extends State<_VideoScrubber> {
...
@@ -102,7 +108,7 @@ class _VideoScrubberState extends State<_VideoScrubber> {
final
Offset
tapPos
=
box
.
globalToLocal
(
globalPosition
);
final
Offset
tapPos
=
box
.
globalToLocal
(
globalPosition
);
final
double
relative
=
tapPos
.
dx
/
box
.
size
.
width
;
final
double
relative
=
tapPos
.
dx
/
box
.
size
.
width
;
final
Duration
position
=
controller
.
value
.
duration
*
relative
;
final
Duration
position
=
controller
.
value
.
duration
*
relative
;
controller
.
seekTo
(
position
);
widget
.
onSeekTo
?.
call
(
position
);
}
}
void
emitDragUpdate
(
globalPosition
)
{
void
emitDragUpdate
(
globalPosition
)
{
...
...
pubspec.yaml
浏览文件 @
3a78419c
...
@@ -11,7 +11,7 @@ dependencies:
...
@@ -11,7 +11,7 @@ dependencies:
flutter
:
flutter
:
sdk
:
flutter
sdk
:
flutter
plugin_platform_interface
:
^2.0.2
plugin_platform_interface
:
^2.0.2
video_player
:
^2.7.
0
video_player
:
^2.7.
2
connectivity
:
^3.0.6
connectivity
:
^3.0.6
screen_brightness
:
^0.2.2+1
screen_brightness
:
^0.2.2+1
wakelock
:
^0.6.2
wakelock
:
^0.6.2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论