下面的代碼或多或少取自示例MPMoviePlayerController示例代碼。在去年我寫的一個應用程序中,它曾經全屏播放視頻而沒有問題。從iOS 4.0開始,只有背景音頻。這就像電影播放器沒有視圖或視圖在我的應用程序後面。我仍然可以與我的應用進行互動,甚至可以「開始」一個新視頻(僅音頻)。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];
}
是的,剛剛發現這一點。謝謝。 – edoloughlin 2010-09-20 10:35:38