当我尝试以下操作时,双击时当前播放的视频会停止,但新视频无法播放。我只是一个黑屏。
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 2;
[self.moviePlayer.view addGestureRecognizer:tap];
- (void)handleTap:(UITapGestureRecognizer *)gesture {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Movie2" ofType:@"mp4"];
[self.moviePlayer setContentURL:[NSURL fileURLWithPath:moviePath]];
NSLog(@"contentURL: %@", self.moviePlayer.contentURL);
}
日志语句正确显示文件://localhost/Users/me/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/15072262-7BC0-42D5-840C-740CF5B97D55/MyApp.app/Movie2.mp4 < / p>
如果我在第一次创建MPMoviePlayerController时将它设置为contentURL,则Movie2.mp4有效并播放。为什么我不能改变播放器的内容?
答案 0 :(得分:2)
实际上我只需要在更改contentURL之后告诉它播放: [self.moviePlayer play];