【问题标题】:Failed to set the initialPlaybackTime for a MPMoviePlayerController when recreating it in the second time第二次重新创建 MPMoviePlayerController 时无法设置它的 initialPlaybackTime
【发布时间】:2010-06-04 05:28:46
【问题描述】:

第一次创建 MPMoviePlayerController(例如 theMovie)时,可以成功设置其 initialPlaybackTime。但是当 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 属性发生了什么吗?

并且每当您重新加载上述代码所在的 viewController(来自父 viewcontroller 的 presentModalViewController)时,电影都可以从任何播放时间开始。我真的很困惑视图控制器加载和发布后重新创建它之间的 MPMoviePlayerController 注册方法有什么区别。

【问题讨论】:

标签: ios objective-c mpmovieplayercontroller playback


【解决方案1】:

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

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

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

【讨论】:

  • 您能解释一下您所说的“完整”版本是什么意思吗?它与[player release], player = nil; 有何不同?
【解决方案2】:

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

[theMovie released]; theMovie = nil;

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多