2

在第一次创建 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 注册方法有什么区别。

4

2 回答 2

1

这个问题已经解决!正确设置 initialPlaybackTime 需要一步。

释放movieplayer后,需要延迟1秒才能重新开始播放。确保电影播放器​​完全释放。

我花了 3 天时间才弄清楚这个问题。但现在我的问题是如何检测电影播放器​​是否已完全释放,而不是等待一秒钟。

于 2010-06-05T03:21:45.007 回答
1

在你发布了你的 theMovie 之后,给它一个值 nil

[theMovie released]; theMovie = nil;

那么你可以判断它是否已经发布。

if (theMovie == nil){
//do something here when movie player is released already
}

于 2010-09-06T02:52:53.387 回答