refactors design to flutter driven service core.
This commit is contained in:
+7
-25
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:just_audio_background/just_audio_background.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:timezone/data/latest.dart' as tz;
|
||||
import 'app_theme_business_object.dart';
|
||||
@@ -12,13 +13,7 @@ import 'streaming_audio_business_object.dart';
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
tz.initializeTimeZones();
|
||||
await JustAudioBackground.init(
|
||||
androidNotificationChannelId: 'com.kryzgoflutter.audio.channel',
|
||||
androidNotificationChannelName: 'KRYZ Audio Playback',
|
||||
androidNotificationOngoing: true,
|
||||
);
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
unawaited(StreamingAudioBusinessObject.initializeBackgroundAudio());
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
@@ -139,11 +134,6 @@ class _MainPageState extends State<MainPage> {
|
||||
_liveInfo.addListener(_handleLiveInfoChanged);
|
||||
_liveInfo.start();
|
||||
_playbackChannel.setMethodCallHandler(_handlePlaybackMethodCall);
|
||||
// Tell native that Flutter is ready to receive method calls.
|
||||
// On Android this unblocks any pending auto_play from Android Auto.
|
||||
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||
_playbackChannel.invokeMethod<void>('flutterReady');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handlePlaybackMethodCall(MethodCall call) async {
|
||||
@@ -163,19 +153,11 @@ class _MainPageState extends State<MainPage> {
|
||||
setState(() {
|
||||
// Rebuild when playback state changes from the player.
|
||||
});
|
||||
|
||||
_syncAutoPlaybackState();
|
||||
}
|
||||
|
||||
void _syncAutoPlaybackState() {
|
||||
if (defaultTargetPlatform != TargetPlatform.android) return;
|
||||
_playbackChannel.invokeMethod<void>('updatePlaybackState', {
|
||||
'isPlaying': _audio.isPlaying,
|
||||
'isBuffering': _audio.isBuffering,
|
||||
});
|
||||
}
|
||||
|
||||
void _handleLiveInfoChanged() {
|
||||
_audio.updateMetadataFromLiveInfo(_liveInfo.snapshot);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
@@ -213,8 +195,8 @@ class _MainPageState extends State<MainPage> {
|
||||
try {
|
||||
await _casting.startCastingLiveStream(
|
||||
streamUrl: _audio.streamUrl,
|
||||
title: 'KRYZ Live Stream',
|
||||
subtitle: 'KRYZ Radio',
|
||||
title: _audio.currentTitle,
|
||||
subtitle: _audio.currentSubtitle,
|
||||
);
|
||||
|
||||
_castStreamStartedForActiveSession = true;
|
||||
|
||||
Reference in New Issue
Block a user