Skip to content

Commit

Permalink
feat: disable/enable smtc on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Apr 14, 2023
1 parent f0b426a commit 7fa50e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
10 changes: 8 additions & 2 deletions lib/services/windows_audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class WindowsAudioService {

final subscriptions = <StreamSubscription>[];

WindowsAudioService(this.ref, this.playlistNotifier) : smtc = SMTCWindows() {
WindowsAudioService(this.ref, this.playlistNotifier)
: smtc = SMTCWindows(enabled: false) {
smtc.setPlaybackStatus(PlaybackStatus.Stopped);
final buttonStream = smtc.buttonPressStream.listen((event) {
switch (event) {
Expand Down Expand Up @@ -50,9 +51,11 @@ class WindowsAudioService {
break;
case PlayerState.stopped:
await smtc.setPlaybackStatus(PlaybackStatus.Stopped);
await smtc.disableSmtc();
break;
case PlayerState.completed:
await smtc.setPlaybackStatus(PlaybackStatus.Changing);
await smtc.disableSmtc();
break;
default:
break;
Expand All @@ -77,12 +80,14 @@ class WindowsAudioService {
}

Future<void> addTrack(Track track) async {
if (!smtc.enabled) {
await smtc.enableSmtc();
}
await smtc.updateMetadata(MusicMetadata(
title: track.name!,
albumArtist: track.artists?.first.name ?? "Unknown",
artist: TypeConversionUtils.artists_X_String<Artist>(track.artists ?? []),
album: track.album?.name ?? "Unknown",
trackNumber: track.trackNumber ?? 0,
thumbnail: TypeConversionUtils.image_X_UrlString(
track.album?.images ?? [],
placeholder: ImagePlaceholder.albumArt,
Expand All @@ -91,6 +96,7 @@ class WindowsAudioService {
}

void dispose() {
smtc.disableSmtc();
smtc.dispose();
for (var element in subscriptions) {
element.cancel();
Expand Down
16 changes: 10 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,11 @@ packages:
flutter_desktop_tools:
dependency: "direct main"
description:
path: "../flutter_desktop_tools"
relative: true
source: path
path: "."
ref: "2fca12d1767dad41421e846383d99ac26e29d202"
resolved-ref: "2fca12d1767dad41421e846383d99ac26e29d202"
url: "https://github.com/KRTirtho/flutter_desktop_tools.git"
source: git
version: "0.0.1"
flutter_distributor:
dependency: "direct dev"
Expand Down Expand Up @@ -1455,9 +1457,11 @@ packages:
smtc_windows:
dependency: "direct main"
description:
path: "../smtc_windows/packages/smtc_windows"
relative: true
source: path
path: "packages/smtc_windows"
ref: "6cc93624b8fab8d7727c8693e91577a7413ccd13"
resolved-ref: "6cc93624b8fab8d7727c8693e91577a7413ccd13"
url: "https://github.com/KRTirtho/smtc_windows.git"
source: git
version: "0.0.1"
source_gen:
dependency: transitive
Expand Down
9 changes: 7 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ dependencies:
path: plugins/window_size
youtube_explode_dart: ^1.12.1
flutter_desktop_tools:
path: ../flutter_desktop_tools
git:
url: https://github.com/KRTirtho/flutter_desktop_tools.git
ref: 2fca12d1767dad41421e846383d99ac26e29d202
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:
build_runner: ^2.3.2
Expand Down

0 comments on commit 7fa50e5

Please sign in to comment.