我的目標是發佈一個電影播放器(theMovie),然後在它完全發佈後開始另一個操作(所謂的playButtonClicked)。我使用了performSelector來延遲「playButtonClicked」1秒,並且效果很好。代碼是:如何知道電影放映人完成發佈?
[theMovie release]; [self performSelector:@selector(playButtonClicked)withObject:nil afterDelay:1];
但是,我不想總是延遲1秒。我想在「theMovie」完全發佈後立即啓動「playButtonClicked」。我嘗試了下面的代碼,但它不起作用,因爲[timer userInfo]永遠不會是零。 有誰知道如何檢查一個電影放映完成。
[theMovie release];
//[self performSelector:@selector(playButtonClicked) withObject:nil afterDelay:1];
NSTimer *atimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self
selector:@selector(waitForReleaseFinish:)
userInfo: (MPMoviePlayerController*) theMovie repeats:YES];
waitForRleaseFinish的代碼:(*的NSTimer)定時器:
if ([timer userInfo]==nil) //here I actually want to test if (theMovie==nil),but I don't know how to do and I'm not sure if it is a correct way to determine the release finished.
{
[timer invalidate];
[self playButtonClicked];
}
期待幫助。謝謝。
謝謝您的回覆。這聽起來有道理。不幸的是,如果我不拖延1-s(甚至0.5s),程序就無法正常工作。電影版本位於「moviePlayerDidFinsh」內,然後開始播放另一部電影。自從{}以來,移動再次被重新創建,它必須首先被釋放。 MPMoviePlayerController * mp = [[MPMoviePlayerController alloc] initWithContentURL:[self getMovieURL]]; \t如果(MP) \t { \t \t //保存電影選手對象 \t \t self.theMovie =熔點; \t \t [mp釋放]; \t} – vicky 2010-06-05 08:15:40
如果電影是保留屬性,它應該自行釋放舊值。所以如果電影是一個保留屬性(它應該是),那麼你不應該手動發佈它。只需調用[self playButtonClicked]並將屬性設置爲新電影播放器時,它將釋放舊電影播放器。 – mk12 2010-06-05 16:36:43