我是编写 Objective-C 的新手。我从 Xcode 4.2 开始。我发现很难找到学习的例子。
最近,我开始编写需要播放 mp4 视频的应用程序。然后我发现 MPMovieplayercontroller 可以提供帮助。
这些是代码(从不同的例子中得出):
-(void)play // a function that trigger by pressing a button
{
[self.view addSubview:self.player.view];
[self.player play];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
screen.backgroundColor = [UIColor redColor];
NSString *videoFilePath = [[NSBundle mainBundle] pathForResource:@"ted" ofType:@"mp4"];
if (videoFilePath == NULL)
{
return;
}
NSURL *videoURL =[NSURL fileURLWithPath:videoFilePath];
self.player.view.frame = CGRectMake(300,300, 400,400);
self.player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
}
它只是行不通。没有任何显示。我确信我的按钮会做出响应并调用正确的功能(播放)。
我还使用配置文件在运行时检查了应用程序。它说发现泄漏。现在我不知道我能做什么。
我也是stackoverflow的新手。如果我问的方式不当,请告诉我。谢谢