在iOS 4中,以下代码可用于播放电影:
现在,我只能看到一个黑屏。没有控件,什么都没有。视频路径是正确的,我已经测试过了。如果我通过按钮点击添加一个白色Subview,它可以工作。所以方法被调用了。
提前致谢!
-(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];
}
现在,我只能看到一个黑屏。没有控件,什么都没有。视频路径是正确的,我已经测试过了。如果我通过按钮点击添加一个白色Subview,它可以工作。所以方法被调用了。
提前致谢!