首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在视频阵列上迭代iOS

在视频阵列上迭代iOS
EN

Stack Overflow用户
提问于 2014-10-12 03:35:09
回答 1查看 107关注 0票数 0

我有一个URL扩展数组。目标是零敲碎打:

  1. 将扩展添加到基本URL以创建特定视频的URL。
  2. 在MPMovieViewController中使用YTViewExtractor播放视频。
  3. 当MPMovieFinishReasonPlaybackEnded = TRUE或next按钮被按下时,重复查找数组中的下一个URL扩展名

这是我迄今为止的工作:

代码语言:javascript
复制
int i;
for (i=0; i < [_uriToBeAppended count]; i++)
{

    NSString *uriString = [_uriToBeAppended  objectAtIndex:i];
    NSString *urlString = [NSString stringWithFormat:@"http://vimeo.com/%@", uriString];

    NSLog(@"URL String: %@", urlString);

    [YTVimeoExtractor fetchVideoURLFromURL:urlString
                                   quality:YTVimeoVideoQualityMedium
                         completionHandler:^(NSURL *videoURL, NSError *error, YTVimeoVideoQuality quality) {
                             if (error) {
                                 // handle error
                                 NSLog(@"Video URL: %@", [videoURL absoluteString]);
                             } else {
                                 // run player
                                 self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
                                 [self.moviePlayer.moviePlayer prepareToPlay];
                                 [self presentViewController:self.moviePlayer animated:YES completion:nil];
                             }
                         }];
}

日志:

代码语言:javascript
复制
    2014-10-11 22:30:05.528 Voulette[668:162653] URL String: http://vimeo.com/96558506
.
.
2014-10-11 22:30:05.577 Voulette[668:162653] URL String: http://vimeo.com/6615855



2014-10-11 22:30:06.997 Voulette[668:162653] -[UIApplication beginIgnoringInteractionEvents] overflow. Ignoring.
.
.
2014-10-11 22:30:09.700 Voulette[668:162653] -[UIApplication beginIgnoringInteractionEvents] overflow. Ignoring.



2014-10-11 22:30:10.063 Voulette[668:162653] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.
.
.
2014-10-11 22:30:10.189 Voulette[668:162653] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.



2014-10-11 22:30:11.519 Voulette[668:162653] Warning: Attempt to present <MPMoviePlayerViewController: 0x1568fcd0> on <ViewController: 0x1554e3e0> whose view is not in the window hierarchy!
.
.
2014-10-11 22:30:11.729 Voulette[668:162653] Warning: Attempt to present <MPMoviePlayerViewController: 0x16818810> on <ViewController: 0x1554e3e0> whose view is not in the window hierarchy!



2014-10-11 22:30:11.739 Voulette[668:162653] -[UIApplication beginIgnoringInteractionEvents] overflow. Ignoring.
2014-10-11 22:30:11.742 Voulette[668:162653] Warning: Attempt to present <MPMoviePlayerViewController: 0x1681d690> on <ViewController: 0x1554e3e0> whose view is not in the window hierarchy!
.
.
2014-10-11 22:30:11.887 Voulette[668:162653] -[UIApplication beginIgnoringInteractionEvents] overflow. Ignoring.
2014-10-11 22:30:11.903 Voulette[668:162653] Warning: Attempt to present <MPMoviePlayerViewController: 0x157b1e70> on <ViewController: 0x1554e3e0> whose view is not in the window hierarchy!



2014-10-11 22:30:12.674 Voulette[668:162653] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.
.
.
2014-10-11 22:30:12.699 Voulette[668:162653] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.

日志表明,for循环在继续执行循环中包含的下一个操作之前对数组中的所有元素进行每个操作。

我所拥有的不是产生期望的产出,我感谢任何反馈或建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-12 05:12:36

因为电影的播放是一个异步事件,所以在第一部电影刚刚开始之前(可能实际上),您的循环将一直执行。您需要将代码放在电影完成时调用的方法中,并使用计数器来跟踪要选择哪个url而不是使用循环。

代码语言:javascript
复制
-(void)playNextMovie {
    static int i = 0;
    if (i < _uriToBeAppended.count) {
        NSString *uriString = [_uriToBeAppended  objectAtIndex:i];
        NSString *urlString = [NSString stringWithFormat:@"http://vimeo.com/%@", uriString];

        NSLog(@"URL String: %@", urlString);

        [YTVimeoExtractor fetchVideoURLFromURL:urlString
                                   quality:YTVimeoVideoQualityMedium
                         completionHandler:^(NSURL *videoURL, NSError *error, YTVimeoVideoQuality quality) {
                             if (error) {
                                 // handle error
                                 NSLog(@"Video URL: %@", [videoURL absoluteString]);
                             } else {
                                 // run player
                                 self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
                                 [self.moviePlayer.moviePlayer prepareToPlay];
                                 [self presentViewController:self.moviePlayer animated:YES completion:nil];
                             }
                         }];
        i++;
    }

}

调用此方法启动第一部电影,然后在调用MPMoviePlayerPlaybackDidFinishNotification时再次调用它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26321602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档