2011-11-07 66 views
0

我有以下代碼:iOS 5的問題與MPMovieDurationAvailableNotification

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:[arr objectAtIndex:0]]]; 
moviePlayer.shouldAutoplay = NO; 
moviePlayer.useApplicationAudioSession = NO; 
//create a NSNotificationCenter which call moviePlaybackComplete function when movie duration available 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDurationAvailable:) name:MPMovieDurationAvailableNotification object:moviePlayer]; 

(void) movieDurationAvailable:(NSNotification *)notification 
{ 
NSLog(@"duration of movie : %f", [moviePlayerController duration]); 
} 

稱爲movieDurationAvailable的方法不會被調用。

你能告訴我我做錯了什麼嗎?

感謝

+0

你沒有開始下載/回放 - 嘗試'[moviePlayer prepareToPlay]' – Till

+0

仍然無法正常工作。 – woody35

+0

普通[moviePlayer play]如何?我必須承認,我從來沒有依賴那個通知,只是簡單地使用了MPMoviePlayerController返回的值。在我的實現中,這是在定時基礎上完成的(例如每0.5秒)。所以,當玩家決定修改估計的遊戲時間時,我的應用程序將從該更正中受益。 – Till

回答

1

如果您使用ARC通知將不會被調用,因爲moviePlayer大概是隻要它超出範圍dealloc'ed。

0

66replica是正確的。在.h文件中聲明moviePlayer,並將[moviePlayer play]添加到上面的代碼中以解決問題。