提交 d260bfe2 authored 作者: kongdywang's avatar kongdywang

1.fix component status conduction error

2.fix slider range error by dart precision problem 3.fix slider buffered progress display error
上级 ba6f7e29
...@@ -43,7 +43,6 @@ class _VideoBottomViewState extends State<VideoBottomView> { ...@@ -43,7 +43,6 @@ class _VideoBottomViewState extends State<VideoBottomView> {
_isShowQuality = isFullScreen; _isShowQuality = isFullScreen;
_currentQuality = widget._playerController.currentQuality; _currentQuality = widget._playerController.currentQuality;
_playerType = widget._playerController.playerType; _playerType = widget._playerController.playerType;
_fixProgress();
super.initState(); super.initState();
} }
...@@ -132,7 +131,7 @@ class _VideoBottomViewState extends State<VideoBottomView> { ...@@ -132,7 +131,7 @@ class _VideoBottomViewState extends State<VideoBottomView> {
min: 0, min: 0,
max: _videoDuration, max: _videoDuration,
value: _currentDuration, value: _currentDuration,
bufferedValue: _playableProgress, bufferedValue: _bufferedDuration,
activeColor: Color(ColorResource.COLOR_MAIN_THEME), activeColor: Color(ColorResource.COLOR_MAIN_THEME),
inactiveColor: Color(ColorResource.COLOR_GRAY), inactiveColor: Color(ColorResource.COLOR_GRAY),
sliderColor: Color(ColorResource.COLOR_MAIN_THEME), sliderColor: Color(ColorResource.COLOR_MAIN_THEME),
...@@ -180,27 +179,11 @@ class _VideoBottomViewState extends State<VideoBottomView> { ...@@ -180,27 +179,11 @@ class _VideoBottomViewState extends State<VideoBottomView> {
_currentDuration = duration; _currentDuration = duration;
_videoDuration = videoDuration; _videoDuration = videoDuration;
_bufferedDuration = bufferedDration; _bufferedDuration = bufferedDration;
_fixProgress();
}); });
} }
} }
} }
void _fixProgress() {
if (_bufferedDuration == 0) {
_playableProgress = 0;
} else {
_playableProgress = _bufferedDuration / _videoDuration;
}
if (_playableProgress < 0) {
_playableProgress = 0;
}
if (_playableProgress > 1) {
_playableProgress = 1;
}
}
void updatePlayState(bool playing) { void updatePlayState(bool playing) {
if (_isPlayMode != playing) { if (_isPlayMode != playing) {
setState(() { setState(() {
...@@ -219,7 +202,7 @@ class _VideoBottomViewState extends State<VideoBottomView> { ...@@ -219,7 +202,7 @@ class _VideoBottomViewState extends State<VideoBottomView> {
void updateUIStatus(int status) { void updateUIStatus(int status) {
setState(() { setState(() {
bool isFullScreen = widget._playerController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE; bool isFullScreen = status == SuperPlayerUIStatus.FULLSCREEN_MODE;
_showFullScreenBtn = !isFullScreen; _showFullScreenBtn = !isFullScreen;
_isShowQuality = isFullScreen; _isShowQuality = isFullScreen;
}); });
......
...@@ -42,15 +42,21 @@ class VideoSlider extends StatefulWidget { ...@@ -42,15 +42,21 @@ class VideoSlider extends StatefulWidget {
this.onDragEnd, this.onDragEnd,
this.canDrag}) { this.canDrag}) {
double range = (max - min); double range = (max - min);
if(range <= 0) { if (range <= 0) {
controller = _VideoSliderController(1, bufferedProgress: 1); controller = _VideoSliderController(1, bufferedProgress: 1);
} else { } else {
double currentProgress = value / range; double currentProgress = remainTwoFixed(value / range);
double? bufferedProgress = bufferedValue != null ? bufferedValue! / range : null; double? bufferedProgress = bufferedValue != null ? remainTwoFixed(bufferedValue! / range) : null;
controller = _VideoSliderController(currentProgress, bufferedProgress: bufferedProgress); controller = _VideoSliderController(currentProgress, bufferedProgress: bufferedProgress);
} }
} }
/// remain two fixed,avoid double precision problem
double remainTwoFixed(double value) {
int valueInt = (value * 100).toInt();
return valueInt / 100;
}
@override @override
State<StatefulWidget> createState() => VideoSliderState(); State<StatefulWidget> createState() => VideoSliderState();
} }
...@@ -82,29 +88,32 @@ class VideoSliderState extends State<VideoSlider> { ...@@ -82,29 +88,32 @@ class VideoSliderState extends State<VideoSlider> {
double rightPadding = overlayRadius; double rightPadding = overlayRadius;
return GestureDetector( return GestureDetector(
onHorizontalDragStart: (DragStartDetails details) { onHorizontalDragStart: (DragStartDetails details) {
if(widget.canDrag!) { if (widget.canDrag!) {
isDraging = true; isDraging = true;
widget.onDragStart?.call(); widget.onDragStart?.call();
} }
}, },
onHorizontalDragUpdate: (DragUpdateDetails details) { onHorizontalDragUpdate: (DragUpdateDetails details) {
if(widget.canDrag!) { if (widget.canDrag!) {
isDraging = true; isDraging = true;
_seekToPosition(details.globalPosition); _seekToPosition(details.globalPosition);
widget.onDragUpdate?.call(widget.controller.progress);} widget.onDragUpdate?.call(widget.controller.progress);
}
}, },
onHorizontalDragEnd: (DragEndDetails details) { onHorizontalDragEnd: (DragEndDetails details) {
if(widget.canDrag!) { if (widget.canDrag!) {
isDraging = false; isDraging = false;
widget.onDragEnd?.call(widget.controller.progress);} widget.onDragEnd?.call(widget.controller.progress);
}
}, },
onHorizontalDragCancel: () { onHorizontalDragCancel: () {
if(widget.canDrag!) { if (widget.canDrag!) {
isDraging = false; isDraging = false;
widget.onDragEnd?.call(widget.controller.progress);} widget.onDragEnd?.call(widget.controller.progress);
}
}, },
onTapDown: (TapDownDetails details) { onTapDown: (TapDownDetails details) {
if(widget.canDrag!) { if (widget.canDrag!) {
_seekToPosition(details.globalPosition); _seekToPosition(details.globalPosition);
} }
}, },
...@@ -174,8 +183,7 @@ class _VideoSliderPainter extends CustomPainter { ...@@ -174,8 +183,7 @@ class _VideoSliderPainter extends CustomPainter {
// draw background // draw background
canvas.drawRRect( canvas.drawRRect(
RRect.fromRectAndRadius( RRect.fromRectAndRadius(Rect.fromPoints(Offset(start, baseVerticalOffset), Offset(end, baseVerticalOffset + progressHeight)),
Rect.fromPoints(Offset(start, baseVerticalOffset), Offset(end, baseVerticalOffset + progressHeight)),
Radius.circular(sliderRadius)), Radius.circular(sliderRadius)),
shaders.backgroundPaint); shaders.backgroundPaint);
...@@ -186,8 +194,7 @@ class _VideoSliderPainter extends CustomPainter { ...@@ -186,8 +194,7 @@ class _VideoSliderPainter extends CustomPainter {
double bufferedEndless = start + (width * bPercent); double bufferedEndless = start + (width * bPercent);
canvas.drawRRect( canvas.drawRRect(
RRect.fromRectAndRadius( RRect.fromRectAndRadius(
Rect.fromPoints( Rect.fromPoints(Offset(start, baseVerticalOffset), Offset(bufferedEndless, baseVerticalOffset + progressHeight)),
Offset(start, baseVerticalOffset), Offset(bufferedEndless, baseVerticalOffset + progressHeight)),
Radius.circular(sliderRadius)), Radius.circular(sliderRadius)),
shaders.bufferedPaint); shaders.bufferedPaint);
} }
...@@ -198,8 +205,7 @@ class _VideoSliderPainter extends CustomPainter { ...@@ -198,8 +205,7 @@ class _VideoSliderPainter extends CustomPainter {
double progressEndless = start + (width * ppercent); double progressEndless = start + (width * ppercent);
canvas.drawRRect( canvas.drawRRect(
RRect.fromRectAndRadius( RRect.fromRectAndRadius(
Rect.fromPoints( Rect.fromPoints(Offset(start, baseVerticalOffset), Offset(progressEndless, baseVerticalOffset + progressHeight)),
Offset(start, baseVerticalOffset), Offset(progressEndless, baseVerticalOffset + progressHeight)),
Radius.circular(sliderRadius)), Radius.circular(sliderRadius)),
shaders.progressPaint); shaders.progressPaint);
...@@ -225,11 +231,7 @@ class _VideoSliderShaders { ...@@ -225,11 +231,7 @@ class _VideoSliderShaders {
Paint dragSliderOverlayPaint = Paint(); Paint dragSliderOverlayPaint = Paint();
_VideoSliderShaders( _VideoSliderShaders(
{Color? backgroundColor, {Color? backgroundColor, Color? progressColor, Color? dragSliderColor, Color? bufferedColor, Color? drawSliderOverlayColor}) {
Color? progressColor,
Color? dragSliderColor,
Color? bufferedColor,
Color? drawSliderOverlayColor}) {
backgroundPaint.color = backgroundColor ?? Colors.grey; backgroundPaint.color = backgroundColor ?? Colors.grey;
bufferedPaint.color = bufferedColor ?? Colors.blueGrey; bufferedPaint.color = bufferedColor ?? Colors.blueGrey;
progressPaint.color = progressColor ?? Colors.blueAccent; progressPaint.color = progressColor ?? Colors.blueAccent;
......
...@@ -220,16 +220,16 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -220,16 +220,16 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
return SuperPlayerFullScreenView(_playController, _superPlayerFullUIController); return SuperPlayerFullScreenView(_playController, _superPlayerFullUIController);
})); }));
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
_playController._updatePlayerUIStatus(SuperPlayerUIStatus.FULLSCREEN_MODE);
_videoBottomKey.currentState?.updateUIStatus(SuperPlayerUIStatus.FULLSCREEN_MODE); _videoBottomKey.currentState?.updateUIStatus(SuperPlayerUIStatus.FULLSCREEN_MODE);
_videoTitleKey.currentState?.updateUIStatus(SuperPlayerUIStatus.FULLSCREEN_MODE); _videoTitleKey.currentState?.updateUIStatus(SuperPlayerUIStatus.FULLSCREEN_MODE);
_playController._updatePlayerUIStatus(SuperPlayerUIStatus.FULLSCREEN_MODE);
hideControlView(); hideControlView();
}, () { }, () {
Navigator.of(context).pop(); Navigator.of(context).pop();
_playController._updatePlayerUIStatus(SuperPlayerUIStatus.WINDOW_MODE);
_videoBottomKey.currentState?.updateUIStatus(SuperPlayerUIStatus.WINDOW_MODE); _videoBottomKey.currentState?.updateUIStatus(SuperPlayerUIStatus.WINDOW_MODE);
_videoTitleKey.currentState?.updateUIStatus(SuperPlayerUIStatus.WINDOW_MODE); _videoTitleKey.currentState?.updateUIStatus(SuperPlayerUIStatus.WINDOW_MODE);
_playController._updatePlayerUIStatus(SuperPlayerUIStatus.WINDOW_MODE);
hideControlView(); hideControlView();
}); });
WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addObserver(this);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论