mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-02-16 22:39:34 +00:00
iii
This commit is contained in:
parent
20a3b95edc
commit
4a7c592e41
9 changed files with 112 additions and 102 deletions
|
|
@ -26,6 +26,7 @@ abstract class AbsAudioPlayer {
|
|||
final chapterStreamController = BehaviorSubject<BookChapter?>.seeded(null);
|
||||
|
||||
BookExpanded? get book => _bookStreamController.nvalue;
|
||||
AudioTrack? get currentTrack => book?.tracks[currentIndex];
|
||||
BookChapter? get currentChapter => chapterStreamController.nvalue;
|
||||
AbsPlayerState get playerState => playerStateSubject.value;
|
||||
Stream<MediaItem?> get mediaItemStream => _mediaItemController.stream;
|
||||
|
|
@ -68,8 +69,8 @@ abstract class AbsAudioPlayer {
|
|||
_mediaItemController.sink.add(item);
|
||||
final playlist = book.tracks
|
||||
.map(
|
||||
(track) => _getUri(currentTrack, downloadedUris,
|
||||
baseUrl: baseUrl, token: token),
|
||||
(track) =>
|
||||
_getUri(track, downloadedUris, baseUrl: baseUrl, token: token),
|
||||
)
|
||||
.toList();
|
||||
await setPlayList(playlist, index: indexTrack, position: positionInTrack);
|
||||
|
|
|
|||
|
|
@ -26,9 +26,13 @@ class AbsPlatformAudioPlayer extends AbsAudioPlayer {
|
|||
);
|
||||
});
|
||||
player.positionStream.distinct().listen((position) {
|
||||
final chapter = book?.findChapterAtTime(positionInBook);
|
||||
if (chapter != currentChapter) {
|
||||
chapterStreamController.add(chapter);
|
||||
final chapter = currentChapter;
|
||||
if (positionInBook <= (chapter?.start ?? Duration.zero) ||
|
||||
positionInBook <= (chapter?.end ?? Duration.zero)) {
|
||||
final chapter = book?.findChapterAtTime(positionInBook);
|
||||
if (chapter != currentChapter) {
|
||||
chapterStreamController.add(chapter);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -103,4 +107,10 @@ class AbsPlatformAudioPlayer extends AbsAudioPlayer {
|
|||
|
||||
@override
|
||||
double get speed => player.speed;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
player.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,34 @@
|
|||
import 'package:audio_service/audio_service.dart';
|
||||
import 'package:audio_session/audio_session.dart';
|
||||
import 'package:vaani/features/player/core/abs_audio_handler.dart' as core;
|
||||
import 'package:vaani/features/player/core/abs_audio_player.dart';
|
||||
import 'package:vaani/globals.dart';
|
||||
// import 'package:audio_service/audio_service.dart';
|
||||
// import 'package:audio_session/audio_session.dart';
|
||||
// import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
// import 'package:vaani/features/player/core/abs_audio_handler.dart' as core;
|
||||
// import 'package:vaani/features/player/core/abs_audio_player.dart';
|
||||
// import 'package:vaani/globals.dart';
|
||||
|
||||
/// 音频播放器 配置
|
||||
Future<void> configurePlayer(AbsAudioPlayer player) async {
|
||||
// for playing audio on windows, linux
|
||||
// /// 音频播放器 配置
|
||||
// @Riverpod(keepAlive: true)
|
||||
// Future<void> configurePlayer(AbsAudioPlayer player) async {
|
||||
// // 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());
|
||||
// // for configuring how this app will interact with other audio apps
|
||||
// final session = await AudioSession.instance;
|
||||
// await session.configure(const AudioSessionConfiguration.speech());
|
||||
|
||||
await AudioService.init(
|
||||
builder: () => core.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),
|
||||
),
|
||||
);
|
||||
// await AudioService.init(
|
||||
// builder: () => core.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),
|
||||
// ),
|
||||
// );
|
||||
|
||||
appLogger.finer('created simple player');
|
||||
}
|
||||
// appLogger.finer('created simple player');
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue