【发布时间】:2010-09-21 14:32:39
【问题描述】:
下面的代码或多或少取自示例 MPMoviePlayerController 示例代码。在我去年编写的一个应用程序中,它曾经可以毫无问题地全屏播放视频。从 iOS 4.0 开始,背景中只有音频。就像电影播放器没有视图或视图在我的应用程序后面。我仍然可以与我的应用互动,甚至“开始”一个新视频(仅限音频)。
就像电影播放器现在需要一个视图,但我没有看到任何在 API 或示例代码中提供它的方式(这似乎是落后一两个版本。
我从一个 URL 加载我的视频,如果我在 Safari 中输入这些视频,它们就可以正常播放。
以下是相关的代码片段,值得一看:
- (void)playMovieUrl:(NSURL*)url
delegate:(id)delegate
callbackSelector:(SEL)selector
{
@try {
movieFinishedCallbackDelegate = delegate;
movieFinishedCallbackSelector = selector;
movieURL = url;
MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie play];
}
@catch (NSException * e) {
return;
}
}
// When the movie is done,release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie release];
[movieURL release];
[movieFinishedCallbackDelegate performSelector:movieFinishedCallbackSelector];
}
【问题讨论】: