我一直在试图弄清楚如何在我的电影视图之上获取“播放符号”,以便用户只需按下该视频即可开始播放视频。有人知道如何实现吗?
-(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;
}
答案 0 :(得分:0)
你可以为你的按钮创建一个IBOutlet,或者你必须通过这样的代码自己添加播放按钮......(为了通过代码访问它。)
// Add play button
playButton = [[UIButton alloc] initWithFrame:CGRectMake(53, 212, 214, 36)];
[playButton setBackgroundImage:[UIImage imageNamed:@"playButton.png"] forState:UIControlStateNormal];
[playButton addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];
[[self view] addSubview:playButton];
一旦你完成了将电影播放器添加到视图中......你需要将播放按钮带到前面......就像....
[self.view bringSubviewToFront:playButton];
请记住,将电影播放器添加到视图后即可完成此操作...