MiniController Progress listener
This commit is contained in:
parent
030adf3920
commit
2fc3f95889
2 changed files with 45 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../cast.dart';
|
||||
import 'MiniControllerProgress.dart';
|
||||
import 'MiniControllerThumbnail.dart';
|
||||
import 'MiniControllerPlayPauseButton.dart';
|
||||
|
||||
|
|
@ -78,11 +79,7 @@ class MiniController extends StatelessWidget {
|
|||
}
|
||||
},
|
||||
),
|
||||
LinearProgressIndicator(
|
||||
color: Colors.red,
|
||||
backgroundColor: Colors.transparent,
|
||||
value: 0.1,
|
||||
),
|
||||
MiniControllerProgress(castFramework: castFramework),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../cast.dart';
|
||||
|
||||
class MiniControllerProgress extends StatelessWidget {
|
||||
final FlutterCastFramework castFramework;
|
||||
|
||||
const MiniControllerProgress({
|
||||
Key? key,
|
||||
required this.castFramework,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var remoteMediaClient =
|
||||
this.castFramework.castContext.sessionManager.remoteMediaClient;
|
||||
|
||||
return StreamBuilder<ProgressInfo>(
|
||||
stream: remoteMediaClient.progressStream,
|
||||
builder: (context, snapshot) {
|
||||
final double progressPercent;
|
||||
|
||||
final progressInfo = snapshot.data;
|
||||
if (snapshot.hasData && progressInfo != null) {
|
||||
final duration = progressInfo.durationMs;
|
||||
final progress = progressInfo.progressMs;
|
||||
|
||||
// this is the denominator, can't be 0
|
||||
final durationFix = duration == 0 ? 1 : duration;
|
||||
progressPercent = progress / durationFix;
|
||||
} else {
|
||||
progressPercent = 0;
|
||||
}
|
||||
|
||||
return LinearProgressIndicator(
|
||||
color: Colors.red,
|
||||
backgroundColor: Colors.transparent,
|
||||
value: progressPercent,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue