Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Last active February 23, 2016 02:35
Show Gist options
  • Save alphaKAI/f9d8a3901fc541c07fdc to your computer and use it in GitHub Desktop.
Save alphaKAI/f9d8a3901fc541c07fdc to your computer and use it in GitHub Desktop.
Get CurrentTrack Information of iTunes(OS X) in Objective-C. (I'm not an Objective-C programmer maybe this code is wrong.)
#include <stdlib.h>
#include <stdbool.h>
// You can generate iTunes.h as follows:
// $ sdef /Applications/iTunes.app | sdp -fh --basename iTunes
#import "iTunes.h"
// For ABI
extern "C" {
struct Music {
const char* name;
const char* album;
const char* artist;
};
bool checkiTunesIsRunning() {
return [[SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"] isRunning];
}
struct Music* getCurrentiTunesPlay() {
iTunesApplication* iTunes;
iTunesTrack* current;
struct Music* music = NULL;
if (!checkiTunesIsRunning()) {
return music;
}
music = (Music*)malloc(sizeof(Music));
iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
current = [iTunes currentTrack];
music->name = [[current name] UTF8String];
music->album = [[current album] UTF8String];
music->artist = [[current artist] UTF8String];
return music;
}
}
// Test
/*
int main() {
struct Music* music;
music = getCurrentiTunesPlay();
if (music == NULL) {
printf("[Fatal Error] - iTunes is not running\n");
return -1;
}
printf("name: %s\n", music->name);
printf("album: %s\n", music->album);
printf("artist: %s\n", music->artist);
free(music);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment