在iOS框架内播放视频(并将其置于中心)

时间:2012-12-28 15:15:23

标签: objective-c ios

我不想全屏播放视频,是否可以在视图中播放视频?

这是我的代码。它确实创建了一个框架并在其中播放视频。问题是我不知道如何在屏幕上居中(它出现在屏幕的右侧)

Screenshot

NSBundle *bundle = [NSBundle mainBundle];
NSURL *url = [NSURL fileURLWithPath:[bundle pathForResource:@"movie" ofType:@"mov"]];

_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
                                       selector:@selector(moviePlayBackDidFinish:)
                                           name:MPMoviePlayerPlaybackDidFinishNotification
                                         object:_moviePlayer];

_moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
_moviePlayer.view.frame = CGRectMake(184, 200, 400, 300);
[self.view addSubview:_moviePlayer.view];
_moviePlayer.shouldAutoplay = YES;

1 个答案:

答案 0 :(得分:1)

替换下面给出的一行将解决您的问题。

_moviePlayer.view.center = self.view.center;