简体   繁体   中英

how to upload mp3 file to php server using MPMediaPickerController in iphone

i am using following code but song not full upload please give me Suggestion.......

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

Follow this link to get mp3, How to get NSData of mp3 using MPMediaPickerController?

Upload your mp3 after Completion of your exporter

 [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];
       }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM