私はディスク上のムービーファイルをリストするUITableViewを持っています。各セル行には、ムービーファイルのサムネイルを生成してその行に表示する期間を取得するために使用される可視行ごとに割り当てられたワーカーインスタンスがあります。なぜMPMovieDurationAvailableNotificationは、自分のMPMoviePlayerControllerの多くのインスタンスに対して一度だけディスパッチされますか?
ムービープレーヤからMPMovieDurationAvailableNotificationイベントをリスンするワーカークラスImのMPMoviePlayerControllerの各インスタンスについて。何らかの理由で、このイベントは、ワーカーインスタンスの1つからディスパッチされた(または少なくともそれをキャッチすることができるだけの)ようです。ここに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は最後の通知のみを送信するように見えます。