2013-05-15 71 views
1

使用MPMediaPickerController PHP服務器我使用下面的代碼,但不是歌完全上傳,請給我建議.......怎樣的mp3文件上傳到iphone

-(void) uploadMusicFile:(MPMediaItem *)song 
    { 
     NSMutableData * fullSongData = [[NSMutableData alloc] init]; 

     NSURL *url = [song valueForProperty: MPMediaItemPropertyAssetURL]; 
     AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: url options:nil]; 

     AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset 
                     presetName: AVAssetExportPresetPassthrough]; 

     exporter.outputFileType = @"public.mpeg-4"; 

     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0]; 

     NSString *exportFile = [documentsDirectory stringByAppendingFormat:@"/%@", 
         @"exported.mp4"]; 

     NSURL *exportURL = [NSURL fileURLWithPath:exportFile]; 
     exporter.outputURL = exportURL; 

     // do the export 
     // (completion handler block omitted) 

     [exporter exportAsynchronouslyWithCompletionHandler: 
     ^{ 
      // Do with data something 
     }]; 

     ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://dev.brsoftech.in/pastor/api/pastor_sermon_sng.php?"]]; 

     // request= [[ASIFormDataRequest alloc]init] ; 
     NSData *data = [NSData dataWithContentsOfFile: exportFile]; 

     // 
     NSString *str =[Base64 encode:data]; 

     [request setPostValue:str forKey:@"sng"]; 
     [request setPostValue:userId forKey:@"id"]; 
     [request setDelegate:self]; 

     waitAlert = [[UIAlertView alloc] initWithTitle:@"Please Wait...." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] ; 

     [waitAlert show]; 

     indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

     // Adjust the indicator so it is up a few pixels from the bottom of the alert 
     indicator.center = CGPointMake(waitAlert.bounds.size.width/2, waitAlert.bounds.size.height - 50); 
     [indicator startAnimating]; 
     [waitAlert addSubview:indicator]; 
    } 
+0

做了一半的負載? – rocky

+0

蘋果公司不會讓你做這樣的事情,我想...... –

回答

0

按照此鏈接來獲得MP3, How to get NSData of mp3 using MPMediaPickerController?

上傳你的MP3你出口後完成

[exporter exportAsynchronouslyWithCompletionHandler: 
     ^{ 
      ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://dev.brsoftech.in/pastor/api/pastor_sermon_sng.php?"]]; 

     // request= [[ASIFormDataRequest alloc]init] ; 
     NSData *data = [NSData dataWithContentsOfFile: exportFile]; 

     // 
     NSString *str =[Base64 encode:data]; 

     [request setPostValue:str forKey:@"sng"]; 
     [request setPostValue:userId forKey:@"id"]; 
     [request setDelegate:self]; 

     waitAlert = [[UIAlertView alloc] initWithTitle:@"Please Wait...." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] ; 

     [waitAlert show]; 

     indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

     // Adjust the indicator so it is up a few pixels from the bottom of the alert 
     indicator.center = CGPointMake(waitAlert.bounds.size.width/2, waitAlert.bounds.size.height - 50); 
     [indicator startAnimating]; 
     [waitAlert addSubview:indicator]; 
     }];