Playlist Generator
1.0
|
00001 // 00002 // EchonestAnalyseConnection.m 00003 // Playlist2 00004 // 00005 // Created by Max Woolf on 31/01/2012. 00006 // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 00007 // 00008 00009 #import "EchonestAnalyseConnection.h" 00010 #import "AVFoundation/AVFoundation.h" 00011 00012 00013 @implementation EchonestAnalyseConnection 00014 00015 -(id)initWithFileURL:(NSString *)theUrl delegate:(id)delegate 00016 { 00017 url = theUrl; 00018 return [self initWithRequest:[self getRequest] delegate:delegate]; 00019 } 00020 00021 -(void)convertToMP4 00022 { 00023 //AVAsset *inputAudio = [AVAsset assetWithURL:[NSURL URLWithString:url]]; 00024 //AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:inputAudio error:nil]; 00025 00026 //AVAssetWriter *writer = [[AVAssetWriter alloc] initWithURL:[self getFilePath] fileType:AVFileTypeAppleM4A error:nil]; 00027 // AVAssetWriterInput *inputWriter = [[AVAssetWriterInput alloc] initWithMediaType:AVFileTypeAppleM4A outputSettings:]; 00028 //[inputWriter appendSampleBuffer:]; 00029 //[writer addInput:inputWriter]; 00030 } 00031 00032 -(NSURL *)getFilePath 00033 { 00034 NSArray *dirPaths; 00035 NSString *docsDir; 00036 dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 00037 docsDir = [dirPaths objectAtIndex:0]; 00038 NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.wav"]; 00039 NSURL *newURL = [[NSURL alloc] initFileURLWithPath:soundFilePath]; 00040 return newURL; 00041 } 00042 00043 -(NSMutableURLRequest *)getRequest 00044 { 00045 [self convertToMP4]; 00046 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://developer.echonest.com/api/v4/track/upload?api_key=BNOAEBT3IZYZI6WXI&filetype=wav&wait=true&bucket=audio_summary"]]; 00047 00048 [request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"]; 00049 [request setHTTPMethod:@"POST"]; 00050 NSData *audioData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]]; 00051 [request setHTTPBody:audioData]; 00052 return request; 00053 } 00054 @end