Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iphone、xcode中播放视频_Iphone_Ios_Objective C_Mpmovieplayercontroller - Fatal编程技术网

如何在iphone、xcode中播放视频

如何在iphone、xcode中播放视频,iphone,ios,objective-c,mpmovieplayercontroller,Iphone,Ios,Objective C,Mpmovieplayercontroller,我正在用iphone创建一个电影应用程序。我想在我的应用程序中播放视频。我的视频url位于本地。请任何人帮助我如何在我的应用程序中播放视频它在本地的什么位置?在应用程序包中? 如果是,URL如下所示: NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"videoname" ofType:@"mov" inDirectory:@""]]; // .h: #import <MediaPlaye

我正在用iphone创建一个电影应用程序。我想在我的应用程序中播放视频。我的视频url位于本地。请任何人帮助我如何在我的应用程序中播放视频

它在本地的什么位置?在应用程序包中? 如果是,URL如下所示:

NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"videoname" ofType:@"mov" inDirectory:@""]];
// .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];
您可以使用苹果的MediaPlayer框架播放大多数视频

将框架(MediaPlayer)添加到项目中,并将其导入
.h
-文件中,然后创建MediaPlayer的实例,如下所示:

NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"videoname" ofType:@"mov" inDirectory:@""]];
// .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];
/.h:
#进口
//.m:
MPMoviePlayerController*player=[[MPMoviePlayerController alloc]initWithContentURL:videoURL];
[[player view]setFrame:[self.view bounds]];//框架必须与父视图匹配
[self.view addSubview:[player view]];
[玩家游戏];
[玩家释放];

此代码适用于:

- (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];

}
-(无效)嵌入YouTube{
//如果url类似于:
//NSString*youtube=@”http://www.youtube.com/watch?v=EVdpzBT7Jrg";
//改为:
NSString*视频URL=@”http://youtube.com/embed/EVdpzBT7Jrg";
NSString*videoHTML=[NSString stringWithFormat:@”\
\
\
\
iframe{位置:绝对;顶部:50%;边缘顶部:-130px;}\
正文{背景色:#000;边距:0;}\
\
\
\
\
\
“,videoURL];
UIWebView*videoView=[[UIWebView alloc]initWithFrame:self.view.frame];
videoView.backgroundColor=[UIColor blackColor];
videoView.不透明=否;
[self.view addSubview:videoView];
[videoView loadHTMLString:videoHTML baseURL:nil];
}

我尝试了
player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@”http://www.youtube.com/watch?v=ukSvjqwJixw"]];,但它不起作用。这个问题是form 2010和iOS 3/4。如果你不能提出一个新问题,试着提出一个新问题。