mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-17 16:07:41 +01:00
media key detection Windows
This commit is contained in:
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@@ -5,7 +5,8 @@
|
||||
{
|
||||
"name": "swiftcontrol",
|
||||
"request": "launch",
|
||||
"type": "dart"
|
||||
"type": "dart",
|
||||
"program": "lib/main.dart"
|
||||
},
|
||||
{
|
||||
"name": "swiftcontrol (profile mode)",
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:gamepads/gamepads.dart';
|
||||
import 'package:media_key_detector/media_key_detector.dart';
|
||||
import 'package:smtc_windows/smtc_windows.dart';
|
||||
import 'package:swift_control/bluetooth/devices/bluetooth_device.dart';
|
||||
import 'package:swift_control/bluetooth/devices/gamepad/gamepad_device.dart';
|
||||
import 'package:swift_control/bluetooth/devices/hid/hid_device.dart';
|
||||
@@ -57,13 +58,68 @@ class Connection {
|
||||
lastLogEntries = lastLogEntries.takeLast(kIsWeb ? 1000 : 60).toList();
|
||||
});
|
||||
|
||||
isMediaKeyDetectionEnabled.addListener(() {
|
||||
isMediaKeyDetectionEnabled.addListener(() async {
|
||||
if (!isMediaKeyDetectionEnabled.value) {
|
||||
|
||||
mediaKeyDetector.setIsPlaying(isPlaying: false);
|
||||
mediaKeyDetector.removeListener(_onMediaKeyDetectedListener);
|
||||
} else {
|
||||
mediaKeyDetector.addListener(_onMediaKeyDetectedListener);
|
||||
mediaKeyDetector.setIsPlaying(isPlaying: true);
|
||||
if (Platform.isWindows) {
|
||||
await SMTCWindows.initialize();
|
||||
|
||||
final smtc = SMTCWindows(
|
||||
metadata: const MusicMetadata(
|
||||
title: 'Title',
|
||||
album: 'Album',
|
||||
albumArtist: 'Album Artist',
|
||||
artist: 'Artist',
|
||||
thumbnail:
|
||||
'https://media.glamour.com/photos/5f4c44e20c71c58fc210d35f/master/w_2560%2Cc_limit/mgid_ao_image_mtv.jpg',
|
||||
),
|
||||
// Timeline info for the OS media player
|
||||
timeline: const PlaybackTimeline(
|
||||
startTimeMs: 0,
|
||||
endTimeMs: 1000,
|
||||
positionMs: 0,
|
||||
minSeekTimeMs: 0,
|
||||
maxSeekTimeMs: 1000,
|
||||
),
|
||||
// Which buttons to show in the OS media player
|
||||
config: const SMTCConfig(
|
||||
fastForwardEnabled: true,
|
||||
nextEnabled: true,
|
||||
pauseEnabled: true,
|
||||
playEnabled: true,
|
||||
rewindEnabled: true,
|
||||
prevEnabled: true,
|
||||
stopEnabled: true,
|
||||
),
|
||||
);
|
||||
smtc.buttonPressStream.listen((event) {
|
||||
print('Event: $event');
|
||||
switch (event) {
|
||||
case PressedButton.play:
|
||||
// Update playback status
|
||||
break;
|
||||
case PressedButton.pause:
|
||||
break;
|
||||
case PressedButton.next:
|
||||
print('Next');
|
||||
break;
|
||||
case PressedButton.previous:
|
||||
print('Previous');
|
||||
break;
|
||||
case PressedButton.stop:
|
||||
smtc.disableSmtc();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mediaKeyDetector.addListener(_onMediaKeyDetectedListener);
|
||||
mediaKeyDetector.setIsPlaying(isPlaying: true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
24
pubspec.lock
24
pubspec.lock
@@ -136,6 +136,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
build_cli_annotations:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build_cli_annotations
|
||||
sha256: e563c2e01de8974566a1998410d3f6f03521788160a02503b0b1f1a46c7b3d95
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -416,6 +424,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.30"
|
||||
flutter_rust_bridge:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_rust_bridge
|
||||
sha256: "37ef40bc6f863652e865f0b2563ea07f0d3c58d8efad803cc01933a4b2ee067e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.11.1"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -1289,6 +1305,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
smtc_windows:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: smtc_windows
|
||||
sha256: dee279b0ddf663c4c729a88bca4e57fb4861aa1b3d01e230bdbf1277b8bfe664
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -20,6 +20,7 @@ dependencies:
|
||||
gamepads: ^0.1.8+2
|
||||
|
||||
path_provider: ^2.1.5
|
||||
smtc_windows: ^1.1.0
|
||||
intl: any
|
||||
version: ^3.0.0
|
||||
bluetooth_low_energy: ^6.1.0
|
||||
|
||||
@@ -18,6 +18,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
flutter_local_notifications_windows
|
||||
smtc_windows
|
||||
)
|
||||
|
||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||
|
||||
Reference in New Issue
Block a user