Created
April 16, 2021 22:20
-
-
Save Hamuko/2a455a0a384ffa8dc1946aff5bf1acec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import MediaPlayer | |
let bundle = CFBundleCreate(kCFAllocatorDefault, NSURL(fileURLWithPath: "/System/Library/PrivateFrameworks/MediaRemote.framework")) | |
let MRMediaRemoteRegisterForNowPlayingNotificationsPointer = CFBundleGetFunctionPointerForName( | |
bundle, "MRMediaRemoteRegisterForNowPlayingNotifications" as CFString | |
) | |
typealias MRMediaRemoteRegisterForNowPlayingNotificationsFunction = @convention(c) (DispatchQueue) -> Void | |
let MRMediaRemoteRegisterForNowPlayingNotifications = unsafeBitCast(MRMediaRemoteRegisterForNowPlayingNotificationsPointer, to: MRMediaRemoteRegisterForNowPlayingNotificationsFunction.self) | |
let MRMediaRemoteGetNowPlayingInfoPointer = CFBundleGetFunctionPointerForName( | |
bundle, "MRMediaRemoteGetNowPlayingInfo" as CFString) | |
typealias MRMediaRemoteGetNowPlayingInfoFunction = @convention(c) (DispatchQueue, @escaping ([String: Any]) -> Void) -> Void | |
let MRMediaRemoteGetNowPlayingInfo = unsafeBitCast( | |
MRMediaRemoteGetNowPlayingInfoPointer, to: MRMediaRemoteGetNowPlayingInfoFunction.self | |
) | |
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "kMRMediaRemoteNowPlayingInfoDidChangeNotification"), object: nil, queue: nil) { (notification) in | |
MRMediaRemoteGetNowPlayingInfo(DispatchQueue.main, { (information) in | |
debugPrint(information["kMRMediaRemoteNowPlayingInfoArtist"] as! String) | |
debugPrint(information["kMRMediaRemoteNowPlayingInfoTitle"] as! String) | |
debugPrint(information["kMRMediaRemoteNowPlayingInfoAlbum"] as! String) | |
}) | |
} | |
MRMediaRemoteRegisterForNowPlayingNotifications(DispatchQueue.main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment