This commit is contained in:
rang 2025-12-09 23:38:51 +08:00
parent 20a3b95edc
commit 4a7c592e41
9 changed files with 112 additions and 102 deletions

View file

@ -1,13 +1,48 @@
import 'package:audio_service/audio_service.dart';
import 'package:audio_session/audio_session.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:shelfsdk/audiobookshelf_api.dart' as api;
import 'package:vaani/api/api_provider.dart';
import 'package:vaani/features/player/core/abs_audio_handler.dart';
import 'package:vaani/features/player/core/abs_audio_player.dart' as core;
import 'package:vaani/features/player/core/abs_audio_player_platform.dart';
part 'abs_provider.g.dart';
// final _logger = Logger('AbsPlayerProvider');
final _logger = Logger('AbsPlayerProvider');
///
@Riverpod(keepAlive: true)
Future<AudioHandler> configurePlayer(Ref ref) async {
final player = ref.read(audioPlayerProvider);
// for playing audio on windows, linux
// for configuring how this app will interact with other audio apps
final session = await AudioSession.instance;
await session.configure(const AudioSessionConfiguration.speech());
final audioService = await AudioService.init(
builder: () => AbsAudioHandler(player),
config: const AudioServiceConfig(
androidNotificationChannelId: 'dr.blank.vaani.channel.audio',
androidNotificationChannelName: 'ABSPlayback',
androidNotificationChannelDescription:
'Needed to control audio from lock screen',
androidNotificationOngoing: false,
androidStopForegroundOnPause: false,
androidNotificationIcon: 'drawable/ic_stat_logo',
preloadArtwork: true,
// fastForwardInterval: Duration(seconds: 20),
// rewindInterval: Duration(seconds: 20),
),
);
_logger.finer('created simple player');
return audioService;
}
/// riverpod状态
@Riverpod(keepAlive: true)
class AudioPlayer extends _$AudioPlayer {
@ -15,6 +50,7 @@ class AudioPlayer extends _$AudioPlayer {
core.AbsAudioPlayer build() {
// final player = AbsMpvAudioPlayer();
final player = AbsPlatformAudioPlayer();
ref.onDispose(player.dispose);
return player;
}

View file

@ -6,6 +6,25 @@ part of 'abs_provider.dart';
// RiverpodGenerator
// **************************************************************************
String _$configurePlayerHash() => r'7e7003c815e7d240a67cd581931839cc60346707';
///
///
/// Copied from [configurePlayer].
@ProviderFor(configurePlayer)
final configurePlayerProvider = FutureProvider<AudioHandler>.internal(
configurePlayer,
name: r'configurePlayerProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$configurePlayerHash,
dependencies: null,
allTransitiveDependencies: null,
);
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef ConfigurePlayerRef = FutureProviderRef<AudioHandler>;
String _$isPlayerActiveHash() => r'71a24418ecf6c1a2d8160b0d0c8fc523d5679e76';
/// See also [isPlayerActive].
@ -58,7 +77,7 @@ final currentChaptersProvider =
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef CurrentChaptersRef = AutoDisposeProviderRef<List<api.BookChapter>>;
String _$audioPlayerHash() => r'26387ece7f0d0c0cc21dc7641853e643866726f6';
String _$audioPlayerHash() => r'e0efa20f340adf3312a76e5ca9e0c8ab0273a22a';
/// riverpod状态
///