2011-02-03 50 views
0

我有一個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只收到最後一次通知。

回答

相關問題