mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
feat: disable/enable smtc on demand
This commit is contained in:
parent
f0b426ae89
commit
7fa50e5c5e
@ -15,7 +15,8 @@ class WindowsAudioService {
|
|||||||
|
|
||||||
final subscriptions = <StreamSubscription>[];
|
final subscriptions = <StreamSubscription>[];
|
||||||
|
|
||||||
WindowsAudioService(this.ref, this.playlistNotifier) : smtc = SMTCWindows() {
|
WindowsAudioService(this.ref, this.playlistNotifier)
|
||||||
|
: smtc = SMTCWindows(enabled: false) {
|
||||||
smtc.setPlaybackStatus(PlaybackStatus.Stopped);
|
smtc.setPlaybackStatus(PlaybackStatus.Stopped);
|
||||||
final buttonStream = smtc.buttonPressStream.listen((event) {
|
final buttonStream = smtc.buttonPressStream.listen((event) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
@ -50,9 +51,11 @@ class WindowsAudioService {
|
|||||||
break;
|
break;
|
||||||
case PlayerState.stopped:
|
case PlayerState.stopped:
|
||||||
await smtc.setPlaybackStatus(PlaybackStatus.Stopped);
|
await smtc.setPlaybackStatus(PlaybackStatus.Stopped);
|
||||||
|
await smtc.disableSmtc();
|
||||||
break;
|
break;
|
||||||
case PlayerState.completed:
|
case PlayerState.completed:
|
||||||
await smtc.setPlaybackStatus(PlaybackStatus.Changing);
|
await smtc.setPlaybackStatus(PlaybackStatus.Changing);
|
||||||
|
await smtc.disableSmtc();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -77,12 +80,14 @@ class WindowsAudioService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addTrack(Track track) async {
|
Future<void> addTrack(Track track) async {
|
||||||
|
if (!smtc.enabled) {
|
||||||
|
await smtc.enableSmtc();
|
||||||
|
}
|
||||||
await smtc.updateMetadata(MusicMetadata(
|
await smtc.updateMetadata(MusicMetadata(
|
||||||
title: track.name!,
|
title: track.name!,
|
||||||
albumArtist: track.artists?.first.name ?? "Unknown",
|
albumArtist: track.artists?.first.name ?? "Unknown",
|
||||||
artist: TypeConversionUtils.artists_X_String<Artist>(track.artists ?? []),
|
artist: TypeConversionUtils.artists_X_String<Artist>(track.artists ?? []),
|
||||||
album: track.album?.name ?? "Unknown",
|
album: track.album?.name ?? "Unknown",
|
||||||
trackNumber: track.trackNumber ?? 0,
|
|
||||||
thumbnail: TypeConversionUtils.image_X_UrlString(
|
thumbnail: TypeConversionUtils.image_X_UrlString(
|
||||||
track.album?.images ?? [],
|
track.album?.images ?? [],
|
||||||
placeholder: ImagePlaceholder.albumArt,
|
placeholder: ImagePlaceholder.albumArt,
|
||||||
@ -91,6 +96,7 @@ class WindowsAudioService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
smtc.disableSmtc();
|
||||||
smtc.dispose();
|
smtc.dispose();
|
||||||
for (var element in subscriptions) {
|
for (var element in subscriptions) {
|
||||||
element.cancel();
|
element.cancel();
|
||||||
|
16
pubspec.lock
16
pubspec.lock
@ -610,9 +610,11 @@ packages:
|
|||||||
flutter_desktop_tools:
|
flutter_desktop_tools:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "../flutter_desktop_tools"
|
path: "."
|
||||||
relative: true
|
ref: "2fca12d1767dad41421e846383d99ac26e29d202"
|
||||||
source: path
|
resolved-ref: "2fca12d1767dad41421e846383d99ac26e29d202"
|
||||||
|
url: "https://github.com/KRTirtho/flutter_desktop_tools.git"
|
||||||
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
flutter_distributor:
|
flutter_distributor:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
@ -1455,9 +1457,11 @@ packages:
|
|||||||
smtc_windows:
|
smtc_windows:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "../smtc_windows/packages/smtc_windows"
|
path: "packages/smtc_windows"
|
||||||
relative: true
|
ref: "6cc93624b8fab8d7727c8693e91577a7413ccd13"
|
||||||
source: path
|
resolved-ref: "6cc93624b8fab8d7727c8693e91577a7413ccd13"
|
||||||
|
url: "https://github.com/KRTirtho/smtc_windows.git"
|
||||||
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
source_gen:
|
source_gen:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
|
@ -83,9 +83,14 @@ dependencies:
|
|||||||
path: plugins/window_size
|
path: plugins/window_size
|
||||||
youtube_explode_dart: ^1.12.1
|
youtube_explode_dart: ^1.12.1
|
||||||
flutter_desktop_tools:
|
flutter_desktop_tools:
|
||||||
path: ../flutter_desktop_tools
|
git:
|
||||||
|
url: https://github.com/KRTirtho/flutter_desktop_tools.git
|
||||||
|
ref: 2fca12d1767dad41421e846383d99ac26e29d202
|
||||||
smtc_windows:
|
smtc_windows:
|
||||||
path: ../smtc_windows/packages/smtc_windows
|
git:
|
||||||
|
url: https://github.com/KRTirtho/smtc_windows.git
|
||||||
|
ref: 6cc93624b8fab8d7727c8693e91577a7413ccd13
|
||||||
|
path: packages/smtc_windows
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.3.2
|
build_runner: ^2.3.2
|
||||||
|
Loading…
Reference in New Issue
Block a user