优化一下通知栏显示

This commit is contained in:
rang 2025-12-07 17:55:07 +08:00
parent d6894c3191
commit f4f860f3ec
12 changed files with 133 additions and 69 deletions

View file

@ -30,7 +30,7 @@ Future<core.AbsAudioHandler> absAudioHandlerInit(Ref ref) async {
await session.configure(const AudioSessionConfiguration.speech());
final audioService = await AudioService.init(
builder: () => core.AbsAudioHandler(),
builder: () => core.AbsAudioHandler(ref),
config: const AudioServiceConfig(
androidNotificationChannelId: 'dr.blank.vaani.channel.audio',
androidNotificationChannelName: 'ABSPlayback',
@ -91,9 +91,9 @@ class AbsState extends _$AbsState {
final initialIndex = book.tracks.indexOf(trackToPlay);
final initialPositionInTrack =
currentTime != null ? currentTime - trackToPlay.startOffset : null;
final title = appSettings.notificationSettings.primaryTitle
final album = appSettings.notificationSettings.primaryTitle
.formatNotificationTitle(book);
final album = appSettings.notificationSettings.secondaryTitle
final artlist = appSettings.notificationSettings.secondaryTitle
.formatNotificationTitle(book);
final id = _getUri(trackToPlay, downloadedUris,
@ -101,10 +101,9 @@ class AbsState extends _$AbsState {
.toString();
final item = MediaItem(
id: id,
title: title,
title: chapterToPlay.title,
album: album,
displayTitle: title,
displaySubtitle: album,
artist: artlist,
duration: chapterToPlay.duration,
artUri: Uri.parse(
'${api.baseUrl}/api/items/${book.libraryItemId}/cover?token=${api.token!}',
@ -154,6 +153,20 @@ class AbsState extends _$AbsState {
Future<void> next() async {}
Future<void> previous() async {}
void updataPlaying(bool playing) {
state = state.copyWith(playing: playing);
}
Stream<Duration> get positionStreamInChapter {
final player = ref.read(absPlayerProvider);
return player.stream.position.distinct().map((position) {
return position +
(state.book?.tracks[state.currentIndex].startOffset ??
Duration.zero) -
(state.currentChapter?.start ?? Duration.zero);
});
}
Uri _getUri(
api.AudioTrack track,
@ -172,3 +185,8 @@ class AbsState extends _$AbsState {
Uri.parse('${baseUrl.toString()}${track.contentUrl}?token=$token');
}
}
@riverpod
Stream<Duration> positionChapter(Ref ref) {
return ref.watch(absStateProvider.notifier).positionStreamInChapter;
}

View file

@ -7,7 +7,7 @@ part of 'abs_provider.dart';
// **************************************************************************
String _$absAudioHandlerInitHash() =>
r'8815383b114e5e3da826afdea58bf0a884b1e3f2';
r'bb46f715e9d51bb6269d0d77e314665601a6bdb0';
/// See also [absAudioHandlerInit].
@ProviderFor(absAudioHandlerInit)
@ -25,6 +25,23 @@ final absAudioHandlerInitProvider =
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef AbsAudioHandlerInitRef = FutureProviderRef<core.AbsAudioHandler>;
String _$positionChapterHash() => r'b1d19345bceb2e54399e15fbb16a534f4be5ba43';
/// See also [positionChapter].
@ProviderFor(positionChapter)
final positionChapterProvider = AutoDisposeStreamProvider<Duration>.internal(
positionChapter,
name: r'positionChapterProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$positionChapterHash,
dependencies: null,
allTransitiveDependencies: null,
);
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef PositionChapterRef = AutoDisposeStreamProviderRef<Duration>;
String _$absPlayerHash() => r'c313a2456bb221b83f3cd2142ae63d6463ef304b';
/// See also [AbsPlayer].
@ -40,7 +57,7 @@ final absPlayerProvider =
);
typedef _$AbsPlayer = Notifier<core.AbsAudioHandler>;
String _$absStateHash() => r'fb11d9d970e0de2dfd722c1f0de2a3b9b10f2859';
String _$absStateHash() => r'6b4ca07c7998304a1522a07b23955c3e54a441e3';
/// See also [AbsState].
@ProviderFor(AbsState)