Skip to content

Commit

Permalink
fix: mobile audio notification not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingkor Roy Tirtho committed Apr 30, 2023
1 parent ce10aa1 commit 8f9303b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/provider/playlist_queue_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {
}

void configure() async {
audioServices = AudioServices(ref, this);
audioServices = await AudioServices.create(ref, this);

audioPlayer.onPlayerComplete.listen((event) async {
if (!isLoaded) return;
Expand Down
22 changes: 16 additions & 6 deletions lib/services/audio_services/audio_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ class AudioServices {
final WindowsAudioService? smtc;
final LinuxAudioService? mpris;

AudioServices._(this.mobile, this.smtc, this.mpris);
AudioServices(this.mobile, this.smtc, this.mpris);

factory AudioServices(Ref ref, PlaylistQueueNotifier playlistQueueNotifier) {
static Future<AudioServices> create(
Ref ref,
PlaylistQueueNotifier playlistQueueNotifier,
) async {
final mobile =
DesktopTools.platform.isMobile || DesktopTools.platform.isMacOS
? MobileAudioService(
playlistQueueNotifier,
ref.read(VolumeProvider.provider.notifier),
? await AudioService.init(
builder: () => MobileAudioService(
playlistQueueNotifier,
ref.read(VolumeProvider.provider.notifier),
),
config: const AudioServiceConfig(
androidNotificationChannelId: 'com.krtirtho.Spotube',
androidNotificationChannelName: 'Spotube',
androidNotificationOngoing: true,
),
)
: null;
final smtc = DesktopTools.platform.isWindows
Expand All @@ -31,7 +41,7 @@ class AudioServices {
? LinuxAudioService(ref, playlistQueueNotifier)
: null;

return AudioServices._(mobile, smtc, mpris);
return AudioServices(mobile, smtc, mpris);
}

Future<void> addTrack(Track track) async {
Expand Down

0 comments on commit 8f9303b

Please sign in to comment.