我认为发布部分给你带来了麻烦,我正在使用这段代码并且工作正常:
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
//// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// /
// ONLY FOR IOS 3.2 or later
if ( kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_2 ) {
// May help to reduce latency
[moviePlayer prepareToPlay];
/// //// //// //// //// //// //// //// //// //// //// //// //// //// /
// Set the correct frame for Movie Controller.
moviePlayer.view.frame = self.view.frame;
/// //// //// //// //// //// //// //// //// //// //// //// //// //// /
// Autorezing the view, allows him to adjust with the orientation.
moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
moviePlayer.view.autoresizesSubviews = YES;
/// //// //// //// //// //// //// //// //// //// //// //// //// //// /
// Add to screen.
[self.view addSubview:moviePlayer.view];
}
//// //// //// ///// //// //// ///// //// //// ///// //// //// ///// //// //// /
// Older than 3.2
else {
// Play Movie.
[moviePlayer play];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
此代码是为所有 iOS 准备的。如果您只支持 < 3.2,请使用正确的部分。
您应该实现一个方法moviePlayBackDidFinish:
以在电影播放完毕时接收通知,如下所示:
//// //// //// ///// //// //// ///// //// //// ///// //// //// ///// //// //// /
// Notification called when the movie finished playing. This Call is only for iOS 3.2
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
// Unregister.
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
// Your finish code here.
}
你必须moviePlayer
在你的 UIViewController和你的方法中声明@interface
dealloc 。dealloc: