我有一个UITableView列出磁盘上的电影文件。对于每个单元行,都会为每个可见行分配一个工作程序实例,用于为电影文件生成缩略图并获取行显示的持续时间。为什么MPMovieDurationAvailableNotification只会为我的MPMoviePlayerController的多个实例调度一次?
对于worker类中的MPMoviePlayerController的每个实例Im正在侦听来自电影播放器的MPMovieDurationAvailableNotification事件。出于某种原因,这个事件似乎只能从其中一个工作者实例中派发(或者至少Im只能捕获它)。这是init和listener代码。有几条评论内联。
- (id) initWithRequestAsset:(RequestAsset *)asset {
if (self = [super init]) {
self.requestAsset = asset;
self.moviePlayer = [MPMoviePlayerController alloc];
[self setupMoviePlayerListeners];
[self.moviePlayer initWithContentURL:self.requestAsset.urlPath];
self.moviePlayer.shouldAutoplay = NO;
// I've also tried to retain the moviePlayer, to no avail
[self.moviePlayer release];
}
return self;
}
- (void) setupMoviePlayerListeners {
//
// If the object: is set to nil then Im able to catch three notifications, but they are all from last instance of the MPMoviePlayerController
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onMovieDurationAvailable:)
name:MPMovieDurationAvailableNotification
object:self.moviePlayer];
}
- (void) onMovieDurationAvailable:(NSNotification *)notification {
NSLog(@"duration received notification");
self.requestAsset.duration = [[notification object] duration];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMovieDurationAvailableNotification object:self.moviePlayer];
}
我在做什么错?我想如果我要设置对象:MPMoviePlayerController的实例的参数,它将允许我只获得该实例的事件。但是,似乎Im只收到最后一次通知。