我有一个控制器,我在其中使用 MPMoviePlayerController 显示视频。我需要在视频上放一张图片。
我正在尝试使用以下代码,但它没有显示出来。我错过了什么?
// method to play the video
- (void)playVideoInLoopMode:(BOOL)loop {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myvideo" ofType:@"m4v"]];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
mp.controlStyle = MPMovieControlStyleNone;
if (loop) {
mp.repeatMode = MPMovieRepeatModeOne;
}
mp.view.frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height);
self.player = mp;
[self.view addSubview:self.player.view];
[self.player prepareToPlay];
[self.player play];
}
// method to add the image
- (void) addImageLayer {
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimage"]];
image.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:image];
}
首先,我使用以下方法运行视频:[self playVideoInLoopMode:YES] 5 秒后,我尝试使用 [self addImageLayer] 方法放置图像层;
在我的 AppDelegate.h 中,我在 didFinishLaunchingWithOptions 中有以下代码:
MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
[self.window addSubview:myVC.view];
[self.window makeKeyAndVisible];