bug fixes for android auto

This commit is contained in:
2026-05-16 21:05:34 -07:00
parent 5ea7442c7c
commit 85740b399b
3 changed files with 59 additions and 14 deletions
+10 -6
View File
@@ -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();
}
+4 -4
View File
@@ -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;