菜鸟教程小白 发表于 2022-12-13 00:13:18

ios - MediaPlayer -requestThumbnailImagesAtTimes 未触发通知


                                            <p><p>我无法使用 <code>MPMoviePlayerController</code> 从电影中提取缩略图图像 </p>

<p><code>-requestThumbnailImagesAtTimes: timeOption:</code></p>

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

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

<h3>最小损坏示例:</h3>

<pre><code>@import MediaPlayer;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// 1. register the observer before requesting the thumbnails
[ addObserverForName:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
    // 4. this never gets hit
    NSLog(@&#34;%@&#34;, note.name);
}];

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

// 3. previously was using integers instead of floats; fixed that but this still doesn&#39;t do anything
timeOption:MPMovieTimeOptionExact];
// ...
}
</code></pre>

<h3>ReactiveCocoa 中的原始示例</h3>

<pre><code>@import MediaPlayer;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// 1. set the file URL
self.viewModel.movieURL = ;
// ...
}

// in viewmodel

- (void)viewDidLoad {
RACSignal *moviePlayerSignal = [ map:^id(NSURL *url) {
    // 2. this allocates correctly
    return [ initWithContentURL:url];
}];

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

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

    // request the thumbnail
    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&#39;t firing notifications :(
    NSLog(@&#34;WHY DOESN&#39;T THIS WORK!?&#34;);
}];
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><pre><code>[ addObserver:self
                                       selector:@selector(didReceiveImage:)
                                             name:MPMoviePlayerThumbnailImageRequestDidFinishNotification
                                           object:self.player];
</code></pre>

<p>查看通知的对象。
您需要将其设置为 MPMoviePlayerController。
所以必须写在MPMoviePlayerController的首字母之后。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - MediaPlayer -requestThumbnailImagesAtTimes 未触发通知,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/25064253/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/25064253/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - MediaPlayer -requestThumbnailImagesAtTimes 未触发通知