diff --git a/lib/carplay_bridge.dart b/lib/carplay_bridge.dart index c30fa9b..e19fec8 100644 --- a/lib/carplay_bridge.dart +++ b/lib/carplay_bridge.dart @@ -57,7 +57,9 @@ class CarPlayBridge { case 'getStateSnapshot': return _snapshot(); default: - throw MissingPluginException('Unknown CarPlay bridge method: ${call.method}'); + throw MissingPluginException( + 'Unknown CarPlay bridge method: ${call.method}', + ); } } @@ -74,4 +76,4 @@ class CarPlayBridge { // Keep playback working even if native sync temporarily fails. } } -} \ No newline at end of file +} diff --git a/lib/kryz_audio_handler.dart b/lib/kryz_audio_handler.dart index b4ae3ae..a8b6df7 100644 --- a/lib/kryz_audio_handler.dart +++ b/lib/kryz_audio_handler.dart @@ -18,7 +18,8 @@ class KryzAudioHandler extends BaseAudioHandler with SeekHandler { static const String streamUrl = 'https://kryz.out.airtime.pro/kryz_a'; static const String mediaId = 'kryz-live-stream'; - static const String _liveInfoEndpoint = 'http://kryz.airtime.pro/api/live-info'; + static const String _liveInfoEndpoint = + 'http://kryz.airtime.pro/api/live-info'; static const Duration _liveInfoTimeout = Duration(seconds: 8); static const Duration _metadataRefreshInterval = Duration(seconds: 20); @@ -27,10 +28,7 @@ class KryzAudioHandler extends BaseAudioHandler with SeekHandler { title: 'KRYZ Live Stream', artist: 'KRYZ Radio', album: 'Live', - extras: { - 'isLive': true, - 'seekable': false, - }, + extras: {'isLive': true, 'seekable': false}, ); final AudioPlayer _player = AudioPlayer(); @@ -82,10 +80,7 @@ class KryzAudioHandler extends BaseAudioHandler with SeekHandler { try { if (!_isSourceLoaded) { await _player.setAudioSource( - AudioSource.uri( - Uri.parse(streamUrl), - tag: mediaItem.value, - ), + AudioSource.uri(Uri.parse(streamUrl), tag: mediaItem.value), ); _isSourceLoaded = true; } @@ -165,25 +160,35 @@ class KryzAudioHandler extends BaseAudioHandler with SeekHandler { } void _onPlayerStateChanged(PlayerState state) { - final AudioProcessingState processingState = switch (state.processingState) { - ProcessingState.idle => AudioProcessingState.idle, - ProcessingState.loading => AudioProcessingState.loading, - ProcessingState.buffering => AudioProcessingState.buffering, - ProcessingState.ready => AudioProcessingState.ready, - ProcessingState.completed => AudioProcessingState.completed, - }; + final AudioProcessingState processingState = + switch (state.processingState) { + ProcessingState.idle => AudioProcessingState.idle, + ProcessingState.loading => AudioProcessingState.loading, + ProcessingState.buffering => AudioProcessingState.buffering, + ProcessingState.ready => AudioProcessingState.ready, + ProcessingState.completed => AudioProcessingState.completed, + }; - final bool isPlaying = state.playing && state.processingState == ProcessingState.ready; - final bool isBuffering = (state.playing && state.processingState != ProcessingState.ready) || - (_playRequested && !state.playing && state.processingState != ProcessingState.completed); + final bool isPlaying = + state.playing && state.processingState == ProcessingState.ready; + final bool isBuffering = + (state.playing && state.processingState != ProcessingState.ready) || + (_playRequested && + !state.playing && + state.processingState != ProcessingState.completed); playbackState.add( playbackState.value.copyWith( controls: [ - if (isPlaying || isBuffering) MediaControl.stop else MediaControl.play, + if (isPlaying || isBuffering) + MediaControl.stop + else + MediaControl.play, ], systemActions: const {}, - processingState: isBuffering ? AudioProcessingState.buffering : processingState, + processingState: isBuffering + ? AudioProcessingState.buffering + : processingState, playing: isPlaying, ), ); @@ -226,4 +231,4 @@ class KryzAudioHandler extends BaseAudioHandler with SeekHandler { // Keep existing metadata if live-info fetch fails. } } -} \ No newline at end of file +} diff --git a/lib/main.dart b/lib/main.dart index 18ba307..45b9c69 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -143,7 +143,7 @@ class _MainPageState extends State with WidgetsBindingObserver { _liveInfo.addListener(_handleLiveInfoChanged); _liveInfo.start(); _playbackChannel.setMethodCallHandler(_handlePlaybackMethodCall); - + // When native code requests local audio to stop (cast media loaded) _casting.onStopLocalAudioRequested = () { unawaited(_audio.stop()); @@ -462,8 +462,7 @@ class _MainPageState extends State with WidgetsBindingObserver { label: const Text('Stop'), ), ElevatedButton.icon( - onPressed: - _casting.status == CastingStatus.connecting + onPressed: _casting.status == CastingStatus.connecting ? null : _toggleCasting, icon: Icon(_castingIcon()),