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