additional carplay changes

This commit is contained in:
2026-05-17 18:35:16 -07:00
parent b8e86263d9
commit c523d0121f
3 changed files with 33 additions and 27 deletions
+3 -1
View File
@@ -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}',
);
}
}
+26 -21
View File
@@ -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: <String, dynamic>{
'isLive': true,
'seekable': false,
},
extras: <String, dynamic>{'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: <MediaControl>[
if (isPlaying || isBuffering) MediaControl.stop else MediaControl.play,
if (isPlaying || isBuffering)
MediaControl.stop
else
MediaControl.play,
],
systemActions: const <MediaAction>{},
processingState: isBuffering ? AudioProcessingState.buffering : processingState,
processingState: isBuffering
? AudioProcessingState.buffering
: processingState,
playing: isPlaying,
),
);
+1 -2
View File
@@ -462,8 +462,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
label: const Text('Stop'),
),
ElevatedButton.icon(
onPressed:
_casting.status == CastingStatus.connecting
onPressed: _casting.status == CastingStatus.connecting
? null
: _toggleCasting,
icon: Icon(_castingIcon()),