ExpandedControlsAdInfoControls handling
This commit is contained in:
parent
255d34c650
commit
066324bd1a
3 changed files with 109 additions and 33 deletions
|
|
@ -12,6 +12,7 @@ typedef AdBreakClipProgressListener = void Function(
|
|||
int durationMs,
|
||||
int whenSkippableMs,
|
||||
);
|
||||
typedef MediaStatusListener = void Function(MediaStatus mediaStatus);
|
||||
|
||||
/// Class for controlling a media player application running on a receiver.
|
||||
class RemoteMediaClient {
|
||||
|
|
@ -40,7 +41,7 @@ class RemoteMediaClient {
|
|||
VoidCallback? onSendingRemoteMediaRequest;
|
||||
|
||||
/// Called when updated ad break status information is received.
|
||||
VoidCallback? onAdBreakStatusUpdated;
|
||||
MediaStatusListener? onAdBreakStatusUpdated;
|
||||
|
||||
/// Called when receiving media error message.
|
||||
VoidCallback? onMediaError;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_cast_framework/src/cast/widgets/expanded_controls/ExpandedControlsAdSkipBox.dart';
|
||||
|
||||
import '../../../../cast.dart';
|
||||
import 'ExpandedControlsConnectedDeviceLabel.dart';
|
||||
import 'ExpandedControlsHighlightedText.dart';
|
||||
import 'ExpandedControlsInfoTextBox.dart';
|
||||
import 'ExpandedControlsAdInfoControls.dart';
|
||||
import 'ExpandedControlsAdSkipBox.dart';
|
||||
import 'ExpandedControlsPlayer.dart';
|
||||
import 'ExpandedControlsProgress.dart';
|
||||
import 'ExpandedControlsToolbar.dart';
|
||||
|
|
@ -137,11 +136,6 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
|||
.updateProgress(progressMs, durationMs, whenSkippableMs);
|
||||
}
|
||||
|
||||
void _onSkipAd() {
|
||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||
sessionManager.remoteMediaClient.skipAd();
|
||||
}
|
||||
|
||||
Widget _getDecoratedToolbar(MediaInfo? mediaInfo) {
|
||||
// Title and subtitle can't be retrieved at the moment
|
||||
// final title = mediaInfo?.mediaMetadata?.strings[MediaMetadataKey.title]
|
||||
|
|
@ -208,29 +202,6 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
|||
);
|
||||
}
|
||||
|
||||
List<Widget> _getAdInfoBox() {
|
||||
return [
|
||||
const Spacer(flex: 2),
|
||||
const ExpandedControlsHighlightedText(
|
||||
text: "Ad Title", // TODO: retrieve ad title from API
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
flex: 8,
|
||||
child: ExpandedControlsInfoTextBox(
|
||||
text: widget.adInfoBoxText,
|
||||
),
|
||||
),
|
||||
const Spacer(flex: 1),
|
||||
ExpandedControlsAdSkipBox(
|
||||
controller: widget.adSkipBoxController,
|
||||
skipAdButtonText: widget.skipAdButtonText,
|
||||
skipAdTimerText: widget.skipAdTimerText,
|
||||
onSkipPressed: _onSkipAd,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Widget _getFullControls(BuildContext context, MediaInfo? mediaInfo) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
|
|
@ -240,7 +211,13 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
|||
child: Column(
|
||||
children: [
|
||||
_getDecoratedToolbar(mediaInfo),
|
||||
..._getAdInfoBox(), // TODO: check if is playing ad, otherwise -> Spacer(),
|
||||
ExpandedControlsAdInfoControls(
|
||||
adSkipBoxController: widget.adSkipBoxController,
|
||||
castFramework: widget.castFramework,
|
||||
adInfoBoxText: widget.adInfoBoxText,
|
||||
skipAdButtonText: widget.skipAdButtonText,
|
||||
skipAdTimerText: widget.skipAdTimerText,
|
||||
),
|
||||
_getDecoratedControls(context, mediaInfo),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,98 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../../cast.dart';
|
||||
import 'ExpandedControlsAdSkipBox.dart';
|
||||
import 'ExpandedControlsHighlightedText.dart';
|
||||
import 'ExpandedControlsInfoTextBox.dart';
|
||||
|
||||
class ExpandedControlsAdInfoControls extends StatefulWidget {
|
||||
final FlutterCastFramework castFramework;
|
||||
|
||||
final ExpandedControlsAdSkipBoxController adSkipBoxController;
|
||||
final String adInfoBoxText;
|
||||
final String? skipAdButtonText;
|
||||
final String? skipAdTimerText;
|
||||
|
||||
const ExpandedControlsAdInfoControls({
|
||||
Key? key,
|
||||
required this.castFramework,
|
||||
required this.adSkipBoxController,
|
||||
this.adInfoBoxText = "",
|
||||
this.skipAdButtonText,
|
||||
this.skipAdTimerText,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ExpandedControlsAdInfoBoxState createState() =>
|
||||
_ExpandedControlsAdInfoBoxState();
|
||||
}
|
||||
|
||||
class _ExpandedControlsAdInfoBoxState
|
||||
extends State<ExpandedControlsAdInfoControls> {
|
||||
bool isPlayingAd = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||
sessionManager.remoteMediaClient.onAdBreakStatusUpdated =
|
||||
_onAdBreakStatusUpdated;
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||
sessionManager.remoteMediaClient.onAdBreakStatusUpdated = null;
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onAdBreakStatusUpdated(MediaStatus mediaStatus) {
|
||||
if (!mounted || mediaStatus.isPlayingAd == null) return;
|
||||
|
||||
if (mediaStatus.isPlayingAd != this.isPlayingAd) {
|
||||
setState(() {
|
||||
if (!mounted) return;
|
||||
this.isPlayingAd = mediaStatus.isPlayingAd ?? false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _onSkipAd() {
|
||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||
sessionManager.remoteMediaClient.skipAd();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!isPlayingAd) {
|
||||
return Spacer();
|
||||
}
|
||||
|
||||
return Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
const Spacer(flex: 2),
|
||||
const ExpandedControlsHighlightedText(
|
||||
text: "Ad Title", // TODO: retrieve ad title from API
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
flex: 8,
|
||||
child: ExpandedControlsInfoTextBox(
|
||||
text: widget.adInfoBoxText,
|
||||
),
|
||||
),
|
||||
const Spacer(flex: 1),
|
||||
ExpandedControlsAdSkipBox(
|
||||
controller: widget.adSkipBoxController,
|
||||
skipAdButtonText: widget.skipAdButtonText,
|
||||
skipAdTimerText: widget.skipAdTimerText,
|
||||
onSkipPressed: _onSkipAd,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue