3
我想使用MPMoviePlayerController在UIView内播放视频。 按下UIButton后,视频出现并开始播放。 不幸的是,在3-4秒后,视频变黑,音频仍在播放。 任何想法? 感谢您的所有时间。几秒钟后视频播放消失
(使用的Xcode 4.2.1)
-(void) playMovieButtonPressed:(UIButton*) button{
NSString* video = @"testmovie.m4v";
NSString *filepath = [[NSBundle mainBundle] pathForResource:[video stringByDeletingPathExtension] ofType:[video pathExtension]];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController* player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
player.movieSourceType = MPMovieSourceTypeFile;
[player.view setFrame:CGRectMake(20, 400, 300, 200)];
[self.view addSubview:player.view];
[player prepareToPlay];
[player play];
}
- (void) moviePlaybackComplete:(NSNotification*) notification {
NSLog(@"videoviewcontroller complete: %@", notification);
MPMoviePlayerController *mymoviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:mymoviePlayerController];
}
这听起来很可笑,你有没有试过另一个视频。我的工作代码几乎完全相同..我所有的扩展类型都是mp4,但我没有使用player.movieSourceType – DJPlayer 2012-02-24 14:13:52
Thx进行回复。好,当然。我测试了其他视频,其他格式和其他来源类型 - 没有运气。我也用一个按钮在一个新的项目中测试了它 - 完全一样的问题。你安装了哪个Xcode版本? – geforce 2012-02-24 15:04:18
同一版本4.2.1 – DJPlayer 2012-02-24 15:27:09