2010-12-07 33 views
0

Je rencontre un problème lors du chargement de vidéo avec mon application. Je vois la vidéo dans Mes vidéos sur YouTube, mais il est dit: "impossible de convertir le fichier vidéo". J'ai téléchargé cette vidéo via le téléverseur YouTube natif avec succès. S'il vous plaît dites-moi ce problème avec mon code, et ce que l'erreur signifie.Téléchargement direct d'Objective-C sur YouTube

code ici:

-(NSString*) GetHeader{ 
     NSString* xml = [[NSString alloc] init]; 
     xml = [xml stringByAppendingString:[NSString stringWithFormat:@"%@ 
%@Content-Type: application/atom+xml; charset=UTF-8%@%@",kboundary, 
klineTerm, klineTerm, klineTerm]]; 

     xml = [xml stringByAppendingString:@"<?xml version=\"1.0\"?>"]; 
     xml = [xml stringByAppendingString:@"<entry xmlns=\"http://www.w3.org/ 
2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:yt= 
\"http://gdata.youtube.com/schemas/2007\"> <media:group><media:title 
type=\"plain\">Movie.m4v</media:title><media:description type=\"plain 
\">I gave a bad toast at my friends wedding.</ 
media:description><media:category scheme=\"http://gdata.youtube.com/ 
schemas/2007/categories.cat\">People</ 
media:category><media:keywords>toast, wedding</media:keywords></ 
media:group></entry>\r\n"]; 

     xml=[xml stringByAppendingString:[NSString stringWithFormat:@"%@ 
%@Content-Type: video/m4v%@Content-Transfer-Encoding: binary%@ 
%@",kboundary,klineTerm,klineTerm,klineTerm,klineTerm]]; 
     return xml; 
} 

-(IBAction)uploadVideoByAuthKey:(id)respons{ 
     NSMutableData* requestBody; 
     const char *utfMyString = [[self GetHeader] UTF8String]; 
     const char *utfMyString1=[[NSString stringWithFormat:@"%@ 
%@--",klineTerm,kboundary] UTF8String]; 
     requestBody=[NSMutableData dataWithBytes:utfMyString 
length:strlen(utfMyString)+1]; 

     //Add video file in body 
     NSURL* URL = [[NSBundle mainBundle] URLForResource:@"Movie" 
withExtension:@"m4v"]; 

     NSData*file=[NSData dataWithContentsOfURL:URL]; 
     [requestBody appendData:file]; 
     [requestBody appendData:[NSData dataWithBytes:utfMyString1 
length:strlen(utfMyString1)+1]]; 

     //Create request 
     NSMutableURLRequest* request = [[NSMutableURLRequest alloc] 
initWithURL:[NSURL URLWithString:kVideoRequestURL]]; 
     [request setHTTPMethod:@"POST"]; 
     [request addValue:[NSString stringWithFormat:@"multipart/related; 
boundary=%@;",kboundaryheader] forHTTPHeaderField:@"Content-Type"]; 
     [request addValue:[NSString stringWithFormat:@"%i",[requestBody 
length]] forHTTPHeaderField:@"Content-Length"]; 
     [request addValue:[NSString stringWithFormat:@"GoogleLogin auth= 
%@",authKey] forHTTPHeaderField:@"Authorization"]; 
     [request addValue:[NSString stringWithFormat:@"key=%@",kdevKey] 
forHTTPHeaderField:@"X-GData-Key"]; 
     [request addValue:[NSString stringWithFormat:@"%@",@"Movie.m4v"] 
forHTTPHeaderField:@"Slug"]; 
     [request addValue:@"add_video_to_youtube" forHTTPHeaderField:@"X- 
GData-Client" ]; 
     [request setHTTPBody: requestBody]; 
} 
+0

Pourquoi ne pas utiliser le [SDK officiel] (http://code.google.com/p/gdata-objectivec -client/)? Avez-vous essayé d'intercepter la requête HTTP pour vous assurer qu'elle n'est pas malformée? – zoul

+0

Je n'ai pas utilisé le SDK officiel car je n'ai besoin que de télécharger le fichier vidéo. Bien sûr, je vais utiliser le SDK officiel si je ne trouve pas de solution à ce problème – Danil

Répondre

0

Essayez de changer Content-Type: video/m4v-Content-Type: video/x-m4v