2013-10-22 107 views
-2

我想捕獲視頻,然後在一些社交網站和電子郵件上共享它,所以我捕獲了視頻並將其保存到相冊中,現在我不知道我怎麼能份額捕獲/保存的視頻,請提出一些對於這一點,這裏是我拍攝的視頻存儲代碼..: -在Facebook,Twitter和電子郵件上捕獲視頻分享

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 
    // NSLog(@"dictionary info %@", info); 

    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath)) 
    { 
     // Copy it to the camera roll. 

     UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), tempFilePath); 

     NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; 

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

     vidPath = [documentsDirectory stringByAppendingFormat:@"/vid1.mp4"]; 
     [vidPath retain]; 

     BOOL success = [videoData writeToFile:vidPath atomically:NO]; 

     NSLog(@"Written file on path success? , %@\n", (success ? @"YES" : @"NO")); 

     [picker dismissModalViewControllerAnimated:YES]; 
    } 
} 

更新

我曾嘗試這個代碼來生成微小的URL共享視頻但它不工作:(

NSString *apiEndpoint = [NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@",vidPath]; 
[apiEndpoint retain]; 

shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint] 
            encoding:NSASCIIStringEncoding 
             error:nil]; 
[shortURL retain]; 

這裏我將能夠存儲視頻照片庫和文件目錄現在我想分享,那麼該怎麼做?請幫忙!

回答

0

對於Facebook來說,在their answer here建議路易斯:

NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"]; 

NSURL *videoPathURL = [[NSURL alloc]initFileURLWithPath:videoPath isDirectory:NO]; 
NSData *videoData = [NSData dataWithContentsOfFile:videoPath]; 

NSString *status = @"One step closer."; 
NSDictionary *params = @{@"title":status, @"description":status}; 

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook 
             requestMethod:SLRequestMethodPOST 
                URL:url 
              parameters:params]; 

[request addMultipartData:videoData 
       withName:@"source" 
        type:@"video/quicktime" 
       filename:[videoPathURL absoluteString]]; 

電子郵件

-(IBAction)sendmailPress:(id)sender 
{ 

MFMailComposeViewController* Apicker = [[MFMailComposeViewController alloc] init]; 
    if (Apicker != nil) 
    { 

     [Apicker setSubject:@""]; 

     [Apicker setMessageBody:@" " isHTML:NO]; 


     [Apicker setToRecipients:toRecipients]; 

     Apicker.mailComposeDelegate = self; 

     NSData *mym=[NSData dataWithContentsOfFile:VideoPath]; 

     NSLog(@"%@",mym); 
     [Apicker addAttachmentData:mym mimeType:@".Extension" fileName:videoname]; 
[self presentModalViewController:Apicker animated:YES]; 
     [Apicker release]; 
} 

enter image description here

enter image description here

+0

這是對您有幫助? – user1673099

+0

實際上我需要一個適用於所有因素的全球解決方案,我想在fb,twitter和電子郵件上分享我拍攝的視頻... –

+0

@ D-eptdeveloper,請參閱我的更新回答。對不起,我不知道推特。 – user1673099

相關問題