mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-30 13:19:44 +02:00
27 lines
1.0 KiB
Dart
27 lines
1.0 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
/// The mini player prepares the current offline cover, paused and silent.
|
|
/// The full player borrows it so opening the route does not restart decoding.
|
|
final playerArtworkVideoProvider = FutureProvider.autoDispose
|
|
.family<VideoPlayerController, String>((ref, source) async {
|
|
final uri = Uri.parse(source);
|
|
if (uri.scheme != 'file') {
|
|
throw ArgumentError('Player artwork must be saved locally');
|
|
}
|
|
final controller = VideoPlayerController.file(
|
|
File.fromUri(uri),
|
|
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
|
|
);
|
|
ref.onDispose(() => unawaited(controller.dispose()));
|
|
await controller.initialize();
|
|
if (!ref.mounted) return controller;
|
|
await controller.setVolume(0);
|
|
if (!ref.mounted) return controller;
|
|
await controller.setLooping(true);
|
|
return controller;
|
|
});
|