mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
fix: use audio_service_mpris plugin
This commit is contained in:
parent
ed6ca006ce
commit
e29cc2578c
@ -4,8 +4,6 @@ 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';
|
||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||
@ -13,49 +11,33 @@ import 'package:spotube/utils/type_conversion_utils.dart';
|
||||
class AudioServices {
|
||||
final MobileAudioService? mobile;
|
||||
final WindowsAudioService? smtc;
|
||||
final LinuxAudioService? mpris;
|
||||
|
||||
AudioServices(this.mobile, this.smtc, this.mpris);
|
||||
AudioServices(this.mobile, this.smtc);
|
||||
|
||||
static Future<AudioServices> create(
|
||||
Ref ref,
|
||||
ProxyPlaylistNotifier playback,
|
||||
) async {
|
||||
final mobile =
|
||||
DesktopTools.platform.isMobile || DesktopTools.platform.isMacOS
|
||||
? await AudioService.init(
|
||||
builder: () => MobileAudioService(playback),
|
||||
config: const AudioServiceConfig(
|
||||
androidNotificationChannelId: 'com.krtirtho.Spotube',
|
||||
androidNotificationChannelName: 'Spotube',
|
||||
androidNotificationOngoing: true,
|
||||
),
|
||||
)
|
||||
: null;
|
||||
final mobile = DesktopTools.platform.isMobile ||
|
||||
DesktopTools.platform.isMacOS ||
|
||||
DesktopTools.platform.isLinux
|
||||
? await AudioService.init(
|
||||
builder: () => MobileAudioService(playback),
|
||||
config: const AudioServiceConfig(
|
||||
androidNotificationChannelId: 'com.krtirtho.Spotube',
|
||||
androidNotificationChannelName: 'Spotube',
|
||||
androidNotificationOngoing: true,
|
||||
),
|
||||
)
|
||||
: null;
|
||||
final smtc = DesktopTools.platform.isWindows
|
||||
? WindowsAudioService(ref, playback)
|
||||
: null;
|
||||
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);
|
||||
return AudioServices(
|
||||
mobile,
|
||||
smtc,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> addTrack(Track track) async {
|
||||
@ -86,6 +68,5 @@ class AudioServices {
|
||||
|
||||
void dispose() {
|
||||
smtc?.dispose();
|
||||
mpris?.dispose();
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.18.12"
|
||||
audio_service_mpris:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: audio_service_mpris
|
||||
sha256: "31be5de2db0c71b217157afce1974ac6d0ad329bd91deb1f19ad094d29340d8e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.0"
|
||||
audio_service_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -113,6 +113,7 @@ dependencies:
|
||||
path: plugins/window_size
|
||||
youtube_explode_dart: ^2.0.1
|
||||
simple_icons: ^7.10.0
|
||||
audio_service_mpris: ^0.1.0
|
||||
|
||||
dev_dependencies:
|
||||
build_runner: ^2.3.2
|
||||
|
Loading…
Reference in New Issue
Block a user