Add state checks in sample
This commit is contained in:
parent
23f70dd444
commit
baa299de58
2 changed files with 39 additions and 8 deletions
|
|
@ -20,6 +20,7 @@ Currently only the following APIs are integrated (both Android and iOS):
|
||||||
* Load RemoteMediaRequestData
|
* Load RemoteMediaRequestData
|
||||||
* Play, Pause, Stop media
|
* Play, Pause, Stop media
|
||||||
* Expanded controls
|
* Expanded controls
|
||||||
|
* Mini Controller
|
||||||
* Cast Button
|
* Cast Button
|
||||||
* Chromecast connection
|
* Chromecast connection
|
||||||
|
|
||||||
|
|
@ -148,8 +149,12 @@ I used this project to test the capabilities of the following technologies:
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
|
Next features to be developed:
|
||||||
|
|
||||||
* CC in Expanded Controls (iOS)
|
* CC in Expanded Controls (iOS)
|
||||||
* Expanded Controls cosmetics (ad in progress bar, full screen, progress bar handle)
|
* Expanded Controls cosmetics (ad in progress bar, full screen, progress bar handle)
|
||||||
|
* Title in MiniController and ExpandedControls (blocked because of a [pigeon issue](https://github.com/flutter/flutter/issues/93464))
|
||||||
* Handle queue
|
* Handle queue
|
||||||
* Handle progress seek
|
* Handle progress seek
|
||||||
* Understand if it is better to refactor using streams instead of listeners
|
* Understand if it is better to refactor using streams instead of listeners
|
||||||
|
* Add tests
|
||||||
|
|
@ -22,6 +22,23 @@ class _MyAppState extends State<MyApp> {
|
||||||
CastState _castState = CastState.idle;
|
CastState _castState = CastState.idle;
|
||||||
SessionState _sessionState = SessionState.idle;
|
SessionState _sessionState = SessionState.idle;
|
||||||
String _message = '';
|
String _message = '';
|
||||||
|
PlayerState _playerState = PlayerState.idle;
|
||||||
|
|
||||||
|
bool get _hasSession => _sessionState == SessionState.started;
|
||||||
|
bool get _hasMedia {
|
||||||
|
if (!_hasSession) return false;
|
||||||
|
|
||||||
|
switch (_playerState) {
|
||||||
|
case PlayerState.idle:
|
||||||
|
case PlayerState.unknown:
|
||||||
|
return false;
|
||||||
|
case PlayerState.loading:
|
||||||
|
case PlayerState.buffering:
|
||||||
|
case PlayerState.paused:
|
||||||
|
case PlayerState.playing:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final textMessageController = TextEditingController();
|
final textMessageController = TextEditingController();
|
||||||
|
|
||||||
|
|
@ -78,9 +95,13 @@ class _MyAppState extends State<MyApp> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onRemoteMediaClientStatusUpdated() {
|
void _onRemoteMediaClientStatusUpdated() {
|
||||||
|
debugPrint("Player state changed from example");
|
||||||
|
setState(() {
|
||||||
final playerState = castFramework
|
final playerState = castFramework
|
||||||
.castContext.sessionManager.remoteMediaClient.playerState.value;
|
.castContext.sessionManager.remoteMediaClient.playerState.value;
|
||||||
debugPrint("RemoteMediaClient status updated - playerState $playerState");
|
|
||||||
|
_playerState = playerState;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSendMessage() {
|
void _onSendMessage() {
|
||||||
|
|
@ -141,13 +162,14 @@ class _MyAppState extends State<MyApp> {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: textMessageController,
|
controller: textMessageController,
|
||||||
|
enabled: _hasSession,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
child: Text('Send'),
|
child: Text('Send'),
|
||||||
onPressed: _onSendMessage,
|
onPressed: _hasSession ? _onSendMessage : null,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|
@ -162,14 +184,18 @@ class _MyAppState extends State<MyApp> {
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
child: Text('Cast video'),
|
child: Text('Cast video'),
|
||||||
onPressed: _onCastVideo,
|
onPressed: _hasSession ? _onCastVideo : null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text("Player State: $_playerState"),
|
||||||
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
child: Text('Expanded Controls'),
|
child: Text('Expanded Controls'),
|
||||||
onPressed: _openExpandedControls,
|
onPressed: _hasMedia ? _openExpandedControls : null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_buildTitle("Mini Controller"),
|
_buildTitle("Mini Controller"),
|
||||||
|
|
@ -177,7 +203,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
child: MiniController(
|
child: MiniController(
|
||||||
castFramework: castFramework,
|
castFramework: castFramework,
|
||||||
onControllerTapped: _openExpandedControls,
|
onControllerTapped: _hasMedia ? _openExpandedControls : null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue