123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- part of 'control_board.dart';
- /// 播放帧位置信息(帧索引、时间索引)
- class LocationInfo extends StatelessWidget {
- LocationInfo({Key? key}) : super(key: key);
- /// 值展示固定宽度
- // ignore: constant_identifier_names
- static const double C_VALUE_DISPLAY_WIDTH = 30.0;
- final playerController = Get.find<IPlayerController>() as VidPlayerController;
- late final int totalFrameCount;
- late final double totalDuration;
- @override
- Widget build(BuildContext context) {
- _initTotalInfo();
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- _buildLabelColumn(),
- SizedBox(
- width: C_VALUE_DISPLAY_WIDTH,
- child: _CurrentValueDisplayColumn(
- totalDuration: totalDuration,
- totalFrameCount: totalFrameCount,
- ),
- ),
- _buildTotalDescColumn(),
- ],
- );
- }
- void _initTotalInfo() {
- final channel = playerController.dataChannel;
- totalFrameCount = channel.imageCount;
- totalDuration = totalFrameCount / channel.probe.frameRate;
- }
- Widget _buildLabelColumn() {
- return _SpanColumn(
- alignment: CrossAxisAlignment.start,
- durationSpan: i18nBook.measure.playLocationDurationLabel.t,
- frameCountSpan: i18nBook.measure.playLocationFrameCountLabel.t,
- );
- }
- Widget _buildTotalDescColumn() {
- final totalDurationStr = '/${totalDuration.toStringAsFixed(1)} s';
- final totalFrameCountStr = '/$totalFrameCount';
- return _SpanColumn(
- durationSpan: totalDurationStr,
- frameCountSpan: totalFrameCountStr,
- );
- }
- }
- class _CurrentValueDisplayColumn extends StatefulWidget {
- const _CurrentValueDisplayColumn({
- Key? key,
- required this.totalDuration,
- required this.totalFrameCount,
- }) : super(key: key);
- final double totalDuration;
- final int totalFrameCount;
- @override
- State<StatefulWidget> createState() => _CurrentValueDisplayColumnState();
- }
- class _CurrentValueDisplayColumnState
- extends State<_CurrentValueDisplayColumn> {
- final playerController = Get.find<IPlayerController>() as VidPlayerController;
- int currentIndex = 0;
- @override
- void initState() {
- playerController.frameUpdated.addListener(_onFrameUpdated);
- super.initState();
- }
- @override
- void dispose() {
- playerController.frameUpdated.addListener(_onFrameUpdated);
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- final currFrameNum = currentIndex + 1;
- double currDuration;
- if (currFrameNum == widget.totalFrameCount) {
- currDuration = widget.totalDuration;
- } else {
- currDuration =
- (currentIndex / widget.totalFrameCount) * widget.totalDuration;
- }
- return _SpanColumn(
- alignment: CrossAxisAlignment.end,
- frameCountSpan: currFrameNum.toString(),
- durationSpan: currDuration.toStringAsFixed(1),
- );
- }
- void _onFrameUpdated(Object sender, VidUsImage frame) {
- if (frame.index == currentIndex) return;
- if (mounted) {
- setState(() {
- currentIndex = frame.index;
- });
- }
- }
- }
- class _SpanColumn extends StatelessWidget {
- const _SpanColumn({
- Key? key,
- this.alignment = CrossAxisAlignment.start,
- this.durationSpan = '',
- this.frameCountSpan = '',
- }) : super(key: key);
- final CrossAxisAlignment alignment;
- final String durationSpan;
- final String frameCountSpan;
- @override
- Widget build(BuildContext context) {
- return Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: alignment,
- children: [
- _buildLine(durationSpan),
- _buildLine(frameCountSpan),
- ],
- );
- }
- Widget _buildLine(String content) {
- return Text(
- content,
- style: const TextStyle(color: Colors.white),
- );
- }
- }
|