2010-09-25 125 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]; 

}