iphone - 为什么 MPMovieDurationAvailableNotification 只为我的 MPMoviePlayerController 的多个实例调度一次?

标签 iphone objective-c events ios grand-central-dispatch

我有一个 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 的实例,它将允许我仅获取该实例的事件。但是,我似乎只收到最后发送的通知。

最佳答案

您只能有 1 个事件的 MPMoviePlayerController 实例。您可以创建多个,但一次只能使用 1 个。

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

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

关于iphone - 为什么 MPMovieDurationAvailableNotification 只为我的 MPMoviePlayerController 的多个实例调度一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4889758/

相关文章:

objective-c - iPhone 在异步 URL 请求中使用互斥体

ios - 在 Objective-C 中是否有可能在运行时找到分配的对象?

javascript - Google Maps JS API 3 - 自定义叠加层中的可编辑表单

html - 如何在DIV中获取按钮而不调用<div>点击事件

c# - 是否有任何事件告诉应用程序何时发生了垃圾收集?

iphone - UIKit 不释放 Controller ,如果它不与动画一起删除?

ios - 激活 iPhone 相机操作使我的应用程序崩溃

iphone - 监测接近度时是否可以不关闭显示?

iphone - 使用 Interface Builder 在屏幕外创建 UIButton

IOS NSString 解码不工作