-
-
Notifications
You must be signed in to change notification settings - Fork 504
Closed
Labels
Description
class NormalClass extends StatefulWidget{ ..... }
void _textToSpeechTaskEntrypoint() async {
AudioServiceBackground.run(() => TextPlayerTask());
}
class _NormalClassNewState extends State<NormalClass>{
final StopWatchTimer stopWatch = StopWatchTimer();
...
some stuff
...
Button(
onTap: () async {
await AudioService.start(
backgroundTaskEntrypoint: _textToSpeechTaskEntrypoint,
androidNotificationChannelName: 'Audio Service Demo',
androidNotificationColor: 0xFF2196f3,
androidNotificationIcon: 'mipmap/ic_launcher',
params: {'title' : (widget.isTimer?'Timer':'StopWatch'), 'stopWatch' : stopWatch}
);
_playSetState(widget.player);
},
type: 'play'),
...
some stuff
...
}
class TextPlayerTask extends BackgroundAudioTask {
...
some stuff
...
@override
Future<void> onStart(Map<String, dynamic> params) async {
playPause();
int second;
while(true){
--> second = params['stopWatch'].rawTime.value; <-- THAT LINE THROWS A RUNTIME ERROR
AudioServiceBackground.setMediaItem(mediaItem(second,params['title']));
AudioServiceBackground.androidForceEnableMediaButtons();
_tts.speak('$second');
// Wait for the speech or a pause request.
await Future.any(
[Future.delayed(Duration(seconds: 1)), _playPauseFuture()]);
// If we were just paused...
if (_playPauseCompleter.isCompleted &&
!_playing &&
_processingState != AudioProcessingState.stopped) {
// Wait to be unpaused...
await _playPauseFuture();
}
}
}
...
some stuff
...
}
(The runtime error: Unhandled Exception: Invalid argument: Instance of 'StopWatchTimer').
How can I properly establish communication between these two Class in order to use the same "StopWatchTimer" instance in both???