2010-10-14 11 views
1

Je veux lire la vidéo Youtube dans mon application avec url.J'ai essayé le code suivant, mais cela ne fonctionne pas.comment lire la vidéo youtube dans l'application iphone?

NSURL *url = [NSURL URLWithString:@"http://www.youtube.com/v/pGqraZN5U0k&amp"]; 
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
    if (moviePlayer) 
    { 
    [self.moviePlayer play]; 
    } 

Aidez-moi s'il vous plaît.

Merci d'avance.

Répondre

1
NSString *youTubeVideoHTML = @"<html><head>\ 
<body style=\"margin:0\">\ 
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ 
width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
</body></html>"; 

NSString *html = [NSString stringWithFormat:youTubeVideoHTML, youtube video link, self.webView.frame.size.width, self.webView.frame.size.height]; 
NSLog(@"html %@",html); 
[self.webView loadHTMLString:html baseURL:nil]; 
+0

mec thax ......... –

2

Les vidéos YouTube ne peuvent pas être lues directement dans MPMoviePlayerController. Vous devrez lancer l'application YouTube ou créer un UIWebView pour afficher la vidéo. Voir la question suivante:

Play youtube videos with MPMoviePlayerController

Questions connexes