Skip to content

Commit

Permalink
fix: linux mpris not showing up and overall media notification service
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jun 2, 2023
1 parent 17e5ab6 commit 1abcad1
Show file tree
Hide file tree
Showing 4 changed files with 753 additions and 102 deletions.
12 changes: 12 additions & 0 deletions lib/provider/proxy_playlist/proxy_playlist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
active: initialIndex,
);

await notificationService.addTrack(addableTrack);

await audioPlayer.openPlaylist(
state.tracks.map(makeAppropriateSource).toList(),
initialIndex: initialIndex,
Expand All @@ -248,6 +250,10 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
}
await audioPlayer.jumpTo(index);

if (oldTrack != null || track != null) {
await notificationService.addTrack(track ?? oldTrack!);
}

if (oldTrack != null && track != null) {
await storeTrack(
oldTrack,
Expand Down Expand Up @@ -316,6 +322,9 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
}
await audioPlayer.skipToNext();

if (oldTrack != null || track != null) {
await notificationService.addTrack(track ?? oldTrack!);
}
if (oldTrack != null && track != null) {
await storeTrack(
oldTrack,
Expand Down Expand Up @@ -344,6 +353,9 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
);
}
await audioPlayer.skipToPrevious();
if (oldTrack != null || track != null) {
await notificationService.addTrack(track ?? oldTrack!);
}
if (oldTrack != null && track != null) {
await storeTrack(
oldTrack,
Expand Down
21 changes: 19 additions & 2 deletions lib/services/audio_services/audio_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/models/spotube_track.dart';
import 'package:spotube/provider/proxy_playlist/proxy_playlist_provider.dart';
import 'package:spotube/services/audio_player/audio_player.dart';
import 'package:spotube/services/audio_services/linux_audio_service.dart';
import 'package:spotube/services/audio_services/mobile_audio_service.dart';
import 'package:spotube/services/audio_services/windows_audio_service.dart';
Expand Down Expand Up @@ -37,19 +38,35 @@ class AudioServices {
final mpris =
DesktopTools.platform.isLinux ? LinuxAudioService(ref, playback) : null;

if (mpris != null) {
playback.addListener((state) {
mpris.player.updateProperties();
});
audioPlayer.playerStateStream.listen((state) {
mpris.player.updateProperties();
});
audioPlayer.positionStream.listen((state) async {
await mpris.player.emitPropertiesChanged(
"org.mpris.MediaPlayer2.Player",
changedProperties: {
"Position": (await mpris.player.getPosition()).returnValues.first,
},
);
});
}

return AudioServices(mobile, smtc, mpris);
}

Future<void> addTrack(Track track) async {
await smtc?.addTrack(track);
await mpris?.addTrack(track);
mobile?.addItem(MediaItem(
id: track.id!,
album: track.album?.name ?? "",
title: track.name!,
artist: TypeConversionUtils.artists_X_String(track.artists ?? <Artist>[]),
duration: track is SpotubeTrack
? track.ytTrack.duration!
? track.ytTrack.duration
: Duration(milliseconds: track.durationMs ?? 0),
artUri: Uri.parse(TypeConversionUtils.image_X_UrlString(
track.album?.images ?? <Image>[],
Expand Down
Loading

0 comments on commit 1abcad1

Please sign in to comment.