2

ムービーからサムネイル画像を抽出するのに問題がありますMPMoviePlayerController

-requestThumbnailImagesAtTimes: timeOption:

すべてを正しく設定したと 99% 確信しています。私はそれらの通知をまったく受け取っていません。

私はもともとで働いていましたReactiveCocoa。可能性を絞り込むために、それなしで最小限の壊れた例があります。

最小限の壊れた例:

@import MediaPlayer;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)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)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)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!?");
  }];
}
4

3 に答える 3

1
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didReceiveImage:)
                                             name:MPMoviePlayerThumbnailImageRequestDidFinishNotification
                                           object:self.player];

通知の対象を参照してください。MPMoviePlayerController として設定する必要があります。そのため、MPMoviePlayerController の頭文字の後に記述する必要があります。

于 2014-09-09T07:49:28.543 に答える
0

requestThumbnailImagesAtTimes: timeOption:ビデオからサムネイルを作成する効果的な方法は、AVAssetImageGenerator を使用することであることがわかりましたが、最初は (thumbnailImageAtTime: deprecated の後) 適切に起動するのに問題がありました。それ以来、私はこの方法を使用してきました。

使用方法については、以前の回答へのリンクを参照してください。

サムネイルImageAtTime: 現在は廃止されています - 代替手段は何ですか?

于 2014-07-31T17:38:08.583 に答える