2010-09-25 223 views

回答

8

它位於何處?在應用程序捆綁中? 如果是這樣,網址是這樣的:

NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"videoname" ofType:@"mov" inDirectory:@""]]; 

您可以與蘋果的MediaPlayer的框架播放大多數視頻。

框架(MediaPlayer的)添加到您的項目,並在.h -file導入它,並創建這樣在MediaPlayer的實例:

// .h: 
#import <MediaPlayer/MediaPlayer.h> 

// .m: 
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 
[[player view] setFrame:[self.view bounds]]; // Frame must match parent view 
[self.view addSubview:[player view]]; 
[player play]; 
[player release]; 

MPMoviePlayerController-documentation

+0

我試着用'player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@「http://www.youtube.com/watch?v=ukSvjqwJixw」]];',但它的不工作。 – 2013-02-04 06:30:22

+0

這個問題是形式2010和iOS 3/4。如果您無法使其工作,請嘗試提出新問題。 – Emil 2013-02-04 17:34:40

0

此代碼:

- (void)embedYouTube { 

    // If the url is like: 
    //NSString *youtube = @"http://www.youtube.com/watch?v=EVdpzBT7Jrg"; 

    // Change to: 
    NSString *videoURL = @"http://youtube.com/embed/EVdpzBT7Jrg"; 

    NSString *videoHTML = [NSString stringWithFormat:@"\ 
       <html>\ 
       <head>\ 
       <style type=\"text/css\">\ 
       iframe {position:absolute; top:50%%; margin-top:-130px;}\ 
       body {background-color:#000; margin:0;}\ 
       </style>\ 
       </head>\ 
       <body>\ 
       <iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\ 
       </body>\ 
       </html>", videoURL]; 
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:self.view.frame]; 
    videoView.backgroundColor = [UIColor blackColor]; 
    videoView.opaque = NO; 
    [self.view addSubview:videoView]; 
    [videoView loadHTMLString:videoHTML baseURL:nil]; 

}