Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
Objective c 电影播放器iOS5在视图上播放符号_Objective C_Ios5_Xcode4.2_Mpmovieplayercontroller - Fatal编程技术网

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