• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - MediaPlayer -requestThumbnailImagesAtTimes 未触发通知

[复制链接]
菜鸟教程小白 发表于 2022-12-13 00:13:18 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我无法使用 MPMoviePlayerController 从电影中提取缩略图图像

-requestThumbnailImagesAtTimes: timeOption:

我 99% 确定我已正确设置所有内容;我根本没有收到这些通知。

我最初在 ReactiveCocoa 工作;为了缩小可能性,我有一个没有它的最小损坏示例。

最小损坏示例:

@import MediaPlayer;

- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info {
  // 1. register the observer before requesting the thumbnails
  [[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
    // 4. this never gets hit
    NSLog(@"%@", note.name);
  }];

  // 2. this works fine - media url is correct etc
  MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[info objectForKey:UIImagePickerControllerMediaURL]];

  // 3. previously was using integers instead of floats; fixed that but this still doesn't do anything
  [moviePlayer requestThumbnailImagesAtTimes[ @0.0f, @1.0f ] timeOption:MPMovieTimeOptionExact];
  // ...
}

ReactiveCocoa 中的原始示例

@import MediaPlayer;

- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info {
  // 1. set the file URL
  self.viewModel.movieURL = [info objectForKey:UIImagePickerControllerMediaURL];
  // ...
}

// in viewmodel

- (void)viewDidLoad {
  RACSignal *moviePlayerSignal = [[RACObserve(self, movieURL) ignore:nil] map:^id(NSURL *url) {
    // 2. this allocates correctly
    return [[MPMoviePlayerController alloc] initWithContentURL:url];
  }];

  // 3. observe the moviePlayerSignal; 
  [[[moviePlayerSignal map:^id(MPMoviePlayerController *player) {
    @strongify(self);
    NSLog(@"%@", player); // checking that the player exists etc - it does; all good here.

    // register the observer before we request the thumbnail
    RACSignal *notification = [[[NSNotificationCenter defaultCenter] rac_addObserverForName:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:player] takeUntil:[self rac_willDeallocSignal]];

    // request the thumbnail
    [player requestThumbnailImagesAtTimes[ @0.0f ] timeOption:MPMovieTimeOptionExact];

    // map the signal into a stream of signals on the observer
    return notification;

    // if we subscribeNext without flattening we correctly get back RACSignals every time 
  }] flatten] subscribeNext:^(id x) {
    // the flattened signal never gets a next because the player isn't firing notifications 
    NSLog(@"WHY DOESN'T THIS WORK!?");
  }];
}



Best Answer-推荐答案


[[NSNotificationCenter defaultCenter] addObserver:self
                                         selectorselector(didReceiveImage
                                             name:MPMoviePlayerThumbnailImageRequestDidFinishNotification
                                           object:self.player];

查看通知的对象。 您需要将其设置为 MPMoviePlayerController。 所以必须写在MPMoviePlayerController的首字母之后。

关于ios - MediaPlayer -requestThumbnailImagesAtTimes 未触发通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25064253/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap