在第一次创建 MPMoviePlayerController(例如,theMovie)时,可以成功设置其初始播放时间。但是当 theMoive 被释放并重新创建一个新的 MPMoviePlayerController 时,它的 intialPlaybackTime 无法正确设置,实际上电影总是从头开始播放。代码如下。
-(void)initAndPlayMovie:(NSURL *)movieURL
{
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
// create a notification for moviePlaybackFinish
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
theMovie.initialPlaybackTime = 15;
[theMovie setScalingMode:MPMovieScalingModeAspectFill];
[theMovie play];}
-(void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController * theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie release];
[self initAndPlayMovie:[self getMovieURL]];
}
使用上面的代码,当 viewcontroller 确实加载并运行 initAndPlayMovie 时,电影从 15 秒开始播放,但是当它播放完成或“完成”被推送时,一个新的 theMovie 被创建并从 0 秒开始播放。有人知道 MPMoviePlayerController 的 initialPlaybackTime 属性发生了什么吗?
并且每当您重新加载上述代码所在的视图控制器(来自父视图控制器的presentModalViewController)时,电影可以从任何播放时间开始。我真的很困惑视图控制器加载和发布后重新创建它之间的 MPMoviePlayerController 注册方法有什么区别。