d70075c426
Adds the Riverpod provider (constructed with dioFactory pulling from the authenticated dioProvider) and extends PlayerActions.playTracks to forward the cache to audio_handler.configure(). The handler signature change lands in the next commit. Intentional intermediate-broken state: audio_handler.configure doesn't yet accept coverCache. Resolved by the next task in the same push. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
48 lines
1.5 KiB
Dart
48 lines
1.5 KiB
Dart
import 'package:audio_service/audio_service.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../auth/auth_provider.dart';
|
|
import '../library/library_providers.dart' show dioProvider;
|
|
import '../models/track.dart';
|
|
import 'album_cover_cache.dart';
|
|
import 'audio_handler.dart';
|
|
|
|
final audioHandlerProvider = Provider<MinstrelAudioHandler>((ref) {
|
|
throw UnimplementedError('overridden in main()');
|
|
});
|
|
|
|
final albumCoverCacheProvider = Provider<AlbumCoverCache>((ref) {
|
|
return AlbumCoverCache(
|
|
dioFactory: () => ref.read(dioProvider.future),
|
|
);
|
|
});
|
|
|
|
final playbackStateProvider = StreamProvider<PlaybackState>(
|
|
(ref) => ref.watch(audioHandlerProvider).playbackState,
|
|
);
|
|
|
|
final mediaItemProvider = StreamProvider<MediaItem?>(
|
|
(ref) => ref.watch(audioHandlerProvider).mediaItem,
|
|
);
|
|
|
|
final queueProvider = StreamProvider<List<MediaItem>>(
|
|
(ref) => ref.watch(audioHandlerProvider).queue,
|
|
);
|
|
|
|
class PlayerActions {
|
|
PlayerActions(this._ref);
|
|
final Ref _ref;
|
|
|
|
Future<void> playTracks(List<TrackRef> tracks, {int initialIndex = 0}) async {
|
|
final url = await _ref.read(serverUrlProvider.future);
|
|
final token = await _ref.read(secureStorageProvider).read(key: 'session_token');
|
|
final cache = _ref.read(albumCoverCacheProvider);
|
|
final h = _ref.read(audioHandlerProvider)
|
|
..configure(baseUrl: url ?? '', token: token, coverCache: cache);
|
|
await h.setQueueFromTracks(tracks, initialIndex: initialIndex);
|
|
await h.play();
|
|
}
|
|
}
|
|
|
|
final playerActionsProvider = Provider<PlayerActions>((ref) => PlayerActions(ref));
|