ERM Channel Video changes
parent
cdd56b2a5a
commit
2682158590
@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
class MyVideoProgressIndicator extends StatefulWidget {
|
||||
const MyVideoProgressIndicator(
|
||||
this.controller, {
|
||||
Key? key,
|
||||
this.colors = const VideoProgressColors(),
|
||||
required this.allowScrubbing,
|
||||
this.padding = const EdgeInsets.only(top: 5.0),
|
||||
}) : super(key: key);
|
||||
|
||||
final VideoPlayerController controller;
|
||||
|
||||
final VideoProgressColors colors;
|
||||
|
||||
final bool allowScrubbing;
|
||||
|
||||
final EdgeInsets padding;
|
||||
|
||||
@override
|
||||
State<MyVideoProgressIndicator> createState() => _VideoProgressIndicatorState();
|
||||
}
|
||||
|
||||
class _VideoProgressIndicatorState extends State<MyVideoProgressIndicator> {
|
||||
_VideoProgressIndicatorState() {
|
||||
listener = () {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
setState(() {});
|
||||
};
|
||||
}
|
||||
|
||||
late VoidCallback listener;
|
||||
|
||||
VideoPlayerController get controller => widget.controller;
|
||||
|
||||
VideoProgressColors get colors => widget.colors;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller.addListener(listener);
|
||||
}
|
||||
|
||||
@override
|
||||
void deactivate() {
|
||||
controller.removeListener(listener);
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget progressIndicator;
|
||||
if (controller.value.isInitialized) {
|
||||
int duration = controller.value.duration.inMilliseconds;
|
||||
int position = controller.value.position.inMilliseconds;
|
||||
|
||||
int maxBuffering = 0;
|
||||
for (DurationRange range in controller.value.buffered) {
|
||||
int end = range.end.inMilliseconds;
|
||||
if (end > maxBuffering) {
|
||||
maxBuffering = end;
|
||||
}
|
||||
}
|
||||
|
||||
progressIndicator = Stack(
|
||||
fit: StackFit.passthrough,
|
||||
children: <Widget>[
|
||||
LinearProgressIndicator(
|
||||
value: maxBuffering / duration,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(colors.bufferedColor),
|
||||
backgroundColor: colors.backgroundColor,
|
||||
minHeight: 8,
|
||||
),
|
||||
LinearProgressIndicator(
|
||||
value: position / duration,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(colors.playedColor),
|
||||
backgroundColor: Colors.transparent,
|
||||
minHeight: 8,
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
progressIndicator = LinearProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(colors.playedColor),
|
||||
backgroundColor: colors.backgroundColor,
|
||||
minHeight: 8,
|
||||
);
|
||||
}
|
||||
Widget paddedProgressIndicator = Padding(
|
||||
padding: widget.padding,
|
||||
child: progressIndicator,
|
||||
);
|
||||
if (widget.allowScrubbing) {
|
||||
return VideoScrubber(
|
||||
controller: controller,
|
||||
child: paddedProgressIndicator,
|
||||
);
|
||||
} else {
|
||||
return paddedProgressIndicator;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue