bug fixes for android auto
This commit is contained in:
+10
-6
@@ -13,13 +13,16 @@ import 'streaming_audio_business_object.dart';
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
tz.initializeTimeZones();
|
||||
unawaited(StreamingAudioBusinessObject.initializeBackgroundAudio());
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
|
||||
runApp(const MyApp());
|
||||
|
||||
// Keep startup non-blocking so UI can render even if background media
|
||||
// services are initializing after an Android Auto cold start.
|
||||
unawaited(
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
@@ -36,6 +39,7 @@ class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
unawaited(_audio.ensureInitialized());
|
||||
_casting.initialize();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,6 @@ enum StreamingPlaybackStatus { stopped, buffering, playing }
|
||||
|
||||
class StreamingAudioBusinessObject extends ChangeNotifier {
|
||||
StreamingAudioBusinessObject() {
|
||||
if (_audioHandler == null && _audioHandlerInitFuture == null) {
|
||||
initializeBackgroundAudio();
|
||||
}
|
||||
|
||||
final initFuture = _audioHandlerInitFuture;
|
||||
if (initFuture != null) {
|
||||
initFuture.then((handler) {
|
||||
@@ -74,6 +70,10 @@ class StreamingAudioBusinessObject extends ChangeNotifier {
|
||||
String get currentTitle => _currentTitle;
|
||||
String get currentSubtitle => _currentSubtitle;
|
||||
|
||||
Future<void> ensureInitialized() async {
|
||||
await initializeBackgroundAudio();
|
||||
}
|
||||
|
||||
StreamingPlaybackStatus _mapPlaybackStateToStatus(PlaybackState state) {
|
||||
if (state.processingState == AudioProcessingState.completed) {
|
||||
return StreamingPlaybackStatus.stopped;
|
||||
|
||||
Reference in New Issue
Block a user