我在实现MPMoviePlayerController时遇到了麻烦。我已下载并运行MoviePlayer应用程序,它工作正常,但我无法在自己的应用程序中重现此功能。我添加了MediaPlayer框架并导入到我的应用程序。
以下是我的代码的相关部分:
UITableViewController类:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==1) {
MyAppDelegate *appDelegate =
(MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate initAndPlayMovie:[self localMovieURL]];
}
}
MyAppDelegate:
-(void)initAndPlayMovie:(NSURL *)movieURL
{
// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{
self.moviePlayer = mp;
[mp release];
[self.moviePlayer play];
}
}
我在
中做了一些调试- (void) moviePreloadDidFinish:(NSNotification*)notification {
NSLog(@"moviePreloadDidFinish");
}
并在
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
NSLog(@"moviePlayBackDidFinish");
}
我注意到电影正确加载并播放,我猜在背景中的某个地方,适当的时间,但我只是看不到电影播放器。视图永远不会改变我的TableViewController!
任何想法?请帮忙!!!