iPhone SDK:如何在视图中播放视频?而不是全屏 [英] iPhone SDK:How do you play video inside a view? Rather than fullscreen
问题描述
我正在尝试在 UIView
中播放视频,所以我的第一步是为该视图添加一个类,并使用以下代码开始在其中播放电影: / p>
I am trying to play video inside a UIView
, so my first step was to add a class for that view and start playing a movie in it using this code:
- (IBAction)movie:(id)sender{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
}
但这只是在应用程序内部使用此方法时崩溃了,但是别的很好。有谁知道如何在视图中播放视频?并避免全屏?
But this just crashes the app when using this method inside it's own class, but is fine elsewhere. Does anyone know how to play video inside a view? and avoid it being full screen?
推荐答案
从3.2 SDK开始,您可以访问的view属性MPMoviePlayerController
,修改其框架并将其添加到视图层次结构中。
As of the 3.2 SDK you can access the view property of MPMoviePlayerController
, modify its frame and add it to your view hierarchy.
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
player.view.frame = CGRectMake(184, 200, 400, 300);
[self.view addSubview:player.view];
[player play];
这里有一个例子: http://www.devx.com/wireless/Article/44642/1954
这篇关于iPhone SDK:如何在视图中播放视频?而不是全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!