1+ ObjC . import ( 'Foundation' ) ;
2+ try {
3+ const frameworkPath = '/System/Library/PrivateFrameworks/MediaRemote.framework' ;
4+ const framework = $ . NSBundle . bundleWithPath ( $ ( frameworkPath ) ) ;
5+ framework . load
6+
7+ const MRNowPlayingRequest = $ . NSClassFromString ( 'MRNowPlayingRequest' ) ;
8+
9+ const playerPath = MRNowPlayingRequest . localNowPlayingPlayerPath ;
10+ const bundleID = ObjC . unwrap ( playerPath . client . bundleIdentifier ) ;
11+
12+ const nowPlayingItem = MRNowPlayingRequest . localNowPlayingItem ;
13+ const info = nowPlayingItem . nowPlayingInfo ;
14+
15+ const title = info . valueForKey ( 'kMRMediaRemoteNowPlayingInfoTitle' ) ;
16+ const album = info . valueForKey ( 'kMRMediaRemoteNowPlayingInfoAlbum' ) ;
17+ const artist = info . valueForKey ( 'kMRMediaRemoteNowPlayingInfoArtist' ) ;
18+ const duration = info . valueForKey ( 'kMRMediaRemoteNowPlayingInfoDuration' ) ;
19+ const playbackStatus = info . valueForKey ( 'kMRMediaRemoteNowPlayingInfoPlaybackRate' ) ;
20+ const elapsed = info . valueForKey ( 'kMRMediaRemoteNowPlayingInfoElapsedTime' ) ;
21+
22+ JSON . stringify ( {
23+ title : ObjC . unwrap ( title ) ,
24+ album : ObjC . unwrap ( album ) ,
25+ artist : ObjC . unwrap ( artist ) ,
26+ duration : ObjC . unwrap ( duration ) ,
27+ playbackStatus : ObjC . unwrap ( playbackStatus ) ,
28+ elapsed : ObjC . unwrap ( elapsed ) ,
29+ player : ObjC . unwrap ( bundleID )
30+ } ) ;
31+ } catch ( error ) {
32+ JSON . stringify ( { player : 'none' , error : error . toString ( ) } ) ;
33+ }
0 commit comments