mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-08 12:09:29 +00:00
feat: extensive settings for media controls through notification (#28)
* feat: add notification settings customisation options * feat: add notification settings page and update routing
This commit is contained in:
parent
721b0a87fc
commit
3cf0a0b124
21 changed files with 1391 additions and 376 deletions
62
lib/features/player/core/init.dart
Normal file
62
lib/features/player/core/init.dart
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import 'package:audio_service/audio_service.dart';
|
||||
import 'package:audio_session/audio_session.dart';
|
||||
import 'package:just_audio_background/just_audio_background.dart'
|
||||
show JustAudioBackground, NotificationConfig;
|
||||
import 'package:just_audio_media_kit/just_audio_media_kit.dart'
|
||||
show JustAudioMediaKit;
|
||||
import 'package:vaani/settings/app_settings_provider.dart';
|
||||
import 'package:vaani/settings/models/app_settings.dart';
|
||||
|
||||
Future<void> configurePlayer() async {
|
||||
// for playing audio on windows, linux
|
||||
JustAudioMediaKit.ensureInitialized();
|
||||
|
||||
// for configuring how this app will interact with other audio apps
|
||||
final session = await AudioSession.instance;
|
||||
await session.configure(const AudioSessionConfiguration.speech());
|
||||
|
||||
final appSettings = loadOrCreateAppSettings();
|
||||
|
||||
// for playing audio in the background
|
||||
await JustAudioBackground.init(
|
||||
androidNotificationChannelId: 'com.vaani.bg_demo.channel.audio',
|
||||
androidNotificationChannelName: 'Audio playback',
|
||||
androidNotificationOngoing: true,
|
||||
androidStopForegroundOnPause: true,
|
||||
androidNotificationChannelDescription: 'Audio playback in the background',
|
||||
androidNotificationIcon: 'drawable/ic_stat_notification_logo',
|
||||
rewindInterval: appSettings.notificationSettings.rewindInterval,
|
||||
fastForwardInterval: appSettings.notificationSettings.fastForwardInterval,
|
||||
androidShowNotificationBadge: false,
|
||||
notificationConfigBuilder: (state) {
|
||||
final controls = [
|
||||
if (appSettings.notificationSettings.mediaControls
|
||||
.contains(NotificationMediaControl.skipToPreviousChapter) &&
|
||||
state.hasPrevious)
|
||||
MediaControl.skipToPrevious,
|
||||
if (appSettings.notificationSettings.mediaControls
|
||||
.contains(NotificationMediaControl.rewind))
|
||||
MediaControl.rewind,
|
||||
if (state.playing) MediaControl.pause else MediaControl.play,
|
||||
if (appSettings.notificationSettings.mediaControls
|
||||
.contains(NotificationMediaControl.fastForward))
|
||||
MediaControl.fastForward,
|
||||
if (appSettings.notificationSettings.mediaControls
|
||||
.contains(NotificationMediaControl.skipToNextChapter) &&
|
||||
state.hasNext)
|
||||
MediaControl.skipToNext,
|
||||
if (appSettings.notificationSettings.mediaControls
|
||||
.contains(NotificationMediaControl.stop))
|
||||
MediaControl.stop,
|
||||
];
|
||||
return NotificationConfig(
|
||||
controls: controls,
|
||||
systemActions: const {
|
||||
MediaAction.seek,
|
||||
MediaAction.seekForward,
|
||||
MediaAction.seekBackward,
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue