Skip to content

Instantly share code, notes, and snippets.

@gsamat
Last active December 23, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsamat/6649607 to your computer and use it in GitHub Desktop.
Save gsamat/6649607 to your computer and use it in GitHub Desktop.
Application -> Build Phases -> Link Binary with Libraries -> Add QTKit.framework
add header to AppDelegate.h
#import <QTKit/QTKit.h>
# in AppDelegate.h
@property (strong) QTMovie *movie;
# start playing track:
NSString *string = ([self.textfield stringValue]);
NSURL *url = [NSURL URLWithString:string];
if ([QTMovie canInitWithURL:url]) {
NSLog(@"can init...");
NSError *error;
self.movie = [QTMovie movieWithURL:url error:(&error)];
NSLog(@"while creating: %@ %@", error, [error userInfo]);
[self.movie autoplay];
//add check if file opened, here
}
else {
NSLog(@"no");
}
# get and play next track
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:@"https://gist.github.com/gsamat/47c715c7fa0c6776aa25/raw"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSError *jsonParsingError = nil;
NSDictionary *track = [NSJSONSerialization JSONObjectWithData:response
options:0 error:&jsonParsingError];
NSLog(@"trackurl:%@",[track objectForKey:@"trackurl"]);
// change track
NSString *string = [track objectForKey:@"trackurl"];
NSURL *url = [NSURL URLWithString:string];
if ([QTMovie canInitWithURL:url]) {
NSLog(@"can init...");
NSError *error;
self.movie = [QTMovie movieWithURL:url error:(&error)];
NSLog(@"while creating: %@ %@", error, [error userInfo]);
[self.movie autoplay];
//add check if file opened, here
}
else {
NSLog(@"no");
}
# play/pause
if ([self.movie rate]==0) {
[self.movie play];
}
else {
[self.movie stop];
}
#icon
NSImage *myImage = [[NSImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://b9hyt39l.zvq.me/3c496646e6c360a0e0ff1fafbf3d60ce1b52f0477a8259975423d935fa2e18db.126x126.jpg"]]];
if ([myImage isValid]) {
NSLog(@"valid");
NSImageView *myView = [[NSImageView alloc] init];
[myView setImage:myImage];
[[NSApp dockTile] setContentView: myView];
[[NSApp dockTile] display];
}
else {
NSLog(@"invalid");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment