2010-06-04 55 views
2

當第一次創建MPMoviePlayerController(例如theMovie)時,其initialPlaybackTime可以成功設置。但是當Moive被釋放並重新創建一個新的MPMoviePlayerController時,它的intialPlaybackTime無法正確設置,實際上電影總是從一開始就播放。代碼如下。第二次重新創建時,無法爲MPMoviePlayerController設置initialPlaybackTime

-(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]]; 
} 

與上面的代碼,當視圖 - 控制做的裝載和運行initAndPlayMovie,電影開始15秒上場,但是當它播放成品或「完成」被按下時,一個新的theMovie創建並開始從0秒開始。有人知道MPMoviePlayerController的initialPlaybackTime屬性發生了什麼嗎?

而且,無論何時重新加載上述代碼所在的viewController(來自父視圖控制器的presentModalViewController),該影片都可以從任何回放時間開始。我真的很困惑MPMoviePlayerController註冊方法與ViewController加載之間的區別是什麼,並且在發佈後重新創建。

+0

[您的問題已經在這裏找到答案(http://stackoverflow.com/questions/1548492/why-is-it-not-possible-to-use-the-mpmovieplayercontroller-more-than -once) – Berik 2011-04-27 12:11:03

回答

1

問題已解決! 它需要一個步驟才能正確設置initialPlaybackTime設置。

發佈影片播放器後,需要1秒的延遲才能開始播放。確保電影放映機完全釋放。

花了我3天的時間才發現問題。但現在我的問題是我如何檢測電影放映人是否已經完全釋放,而不是等待一秒鐘。

+2

你能解釋一下「完整」版本是什麼意思,它與'[player release],player = nil;'有什麼不同? – 2011-07-21 03:38:42

1

您已經發布您的theMovie後,把它的值爲零

[theMovie released]; theMovie = nil;

那麼你就可以判斷它釋放了。

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

相關問題