PlayerLink/src/backends/darwin.mm

32 lines
1.2 KiB
Plaintext
Raw Normal View History

#ifdef __APPLE__
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
2024-11-05 11:33:18 +01:00
#include <dispatch/dispatch.h>
#include "../MediaRemote.hpp"
#include "../backend.hpp"
std::shared_ptr<MediaInfo> backend::getMediaInformation() {
2024-11-05 11:33:18 +01:00
std::string appName = "";
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
MRMediaRemoteGetNowPlayingApplicationPID(dispatch_get_main_queue(), ^(pid_t pid) {
if (pid > 0) {
NSRunningApplication *app = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
2024-11-05 11:33:18 +01:00
if (app)
appName = app.bundleIdentifier
}
2024-11-05 11:33:18 +01:00
dispatch_semaphore_signal(semaphore);
});
MRMediaRemoteGetNowPlayingInfo(dispatch_get_main_queue(), ^(CFDictionaryRef result) {
if (result) {
NSDictionary *playingInfo = (__bridge NSDictionary *)(result);
NSLog(@"Now Playing Info: %@", playingInfo);
}
2024-11-05 11:33:18 +01:00
dispatch_semaphore_signal(semaphore);
});
2024-11-05 11:33:18 +01:00
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_release(semaphore);
return nullptr;
}
bool backend::toggleAutostart(bool enabled) { return false; }
#endif