2011-11-07 67 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]添加到上面的代码中以解决问题。