【发布时间】:2011-10-28 14:29:33
【问题描述】:
在 iOS 4 中,这段代码可以播放电影:
-(IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"testbild1" ofType:@"m4v"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[testview addSubview:moviePlayer.view];
[self.view addSubview:testview];
//[self.view addSubview:moviePlayer.view];
//[moviePlayer setFullscreen:YES animated:YES];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
//[moviePlayerController release];
}
现在,我只得到一个黑屏。没有控制,什么都没有。视频路径是正确的,我测试过了。如果我通过按钮单击添加一个白色的子视图,它就可以工作。所以方法被调用了。
提前致谢!
【问题讨论】:
标签: ios media-player mpmovieplayercontroller