Objective c 电影播放器iOS5在视图上播放符号
我一直在想如何在我的电影视图上添加“播放符号”,这样用户只需按下该按钮,视频就可以开始了。有人知道如何实现吗Objective c 电影播放器iOS5在视图上播放符号,objective-c,ios5,xcode4.2,mpmovieplayercontroller,Objective C,Ios5,Xcode4.2,Mpmovieplayercontroller,我一直在想如何在我的电影视图上添加“播放符号”,这样用户只需按下该按钮,视频就可以开始了。有人知道如何实现吗 -(void)viewDidLoad { //Video player NSString *url = [[NSBundle mainBundle] pathForResource:self.navigationItem.title ofType:@"mov"]; _player = [[MPMoviePlayerController alloc] initWithContentURL
-(void)viewDidLoad
{
//Video player
NSString *url = [[NSBundle mainBundle] pathForResource:self.navigationItem.title ofType:@"mov"];
_player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath: url]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:_player];
_player.view.frame = CGRectMake( 350, 200, 400, 400);
[self.view addSubview:_player.view];
}
//Plays the movie once the "Play" button is pressed
-(IBAction)playMovie
{
[_player play];
}
//Exits fullscreen when movie is finished
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
_player.fullscreen = NO;
}
你可以为你的按钮创建一个IBOutlet,或者你必须自己通过这样的代码添加播放按钮。。。(以便通过代码访问。) 一旦你把电影播放器添加到视图中。。。。你需要把播放按钮放在前面,就像
[self.view bringSubviewToFront:playButton];
请记住,一旦您将电影播放器添加到视图中,就要执行此操作
来源
[self.view bringSubviewToFront:playButton];