0

我有一个 UITableView,它列出了磁盘上的电影文件。对于每个单元格行,为每个可见行分配一个工作实例,用于为电影文件生成缩略图并获取其在行中显示的持续时间。

对于工作类中的每个 MPMoviePlayerController 实例,我正在监听来自电影播放器​​的 MPMovieDurationAvailableNotification 事件。由于某种原因,这个事件似乎只能从其中一个工作实例中分派(或者至少我只能捕获它)。这是初始化和侦听器代码。内联有一些评论。

- (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];

}

我究竟做错了什么?我想如果我将 object: 参数设置为 MPMoviePlayerController 的实例,它将只允许我获取该实例的事件。但是,我似乎只收到了最后一次发送的通知。

4

1 回答 1

1

您只能有 1 个活动的 MPMoviePlayerController 实例。您可以创建多个,但一次只能创建 1 个。

请参阅(大约 2 个屏幕向下):http: //developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html

“注意:虽然您可以创建多个 MPMoviePlayerController 对象并在界面中显示它们的视图,但一次只有一个电影播放器​​可以播放其电影。”

于 2011-11-09T18:48:05.587 回答