MPMovieDurationAvailableNotification的iOS 5问题

时间:2011-11-07 08:49:41

标签: ios5 mpmovieplayercontroller

我有以下代码:

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的方法。

你能告诉我我做错了吗?

由于

2 个答案:

答案 0 :(得分:1)

如果你正在使用ARC,通知将不会被调用,因为一旦超出范围,moviePlayer可能会被释放。

答案 1 :(得分:0)

66replica是正确的。改为在.h文件中声明moviePlayer并将[moviePlayer play]添加到上面的代码中以解决问题。