1

我正在使用以下代码但歌曲未完整上传请给我建议.......

-(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];
   }
4

1 回答 1

0

按照此链接获取 mp3,如何使用 MPMediaPickerController 获取 mp3 的 NSData?

完成导出器后上传您的 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];
       }];
于 2013-06-15T07:27:29.967 回答