gpt4 book ai didi

ios - 迭代视频数组 iOS

转载 作者:行者123 更新时间:2023-11-29 02:36:22 26 4
gpt4 key购买 nike

我有一组 URL 扩展。目标是分段的:

  1. 将扩展名添加到基本网址以创建特定视频的网址。

  2. 使用 YTViewExtractor 在 MPMovieViewController 中播放视频。

  3. 当 MPMovieFinishReasonPlaybackEnded = TRUE 或按下下一个按钮时,重复数组中的下一个 URL 扩展

这是我迄今为止的工作:

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];
}
}];
}

日志:

    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 循环在继续执行循环中包含的下一个操作之前,会遍历数组中所有元素的每个操作。

我所拥有的并没有产生所需的输出,我很感激任何反馈或建议。

最佳答案

由于电影的播放是一个异步事件,您的循环将在第一部电影几乎还没有开始之前(可能在实际之前)一直执行。您需要将代码放在电影播放结束时调用的方法中,并使用计数器来跟踪要选择的 url,而不是使用循环。

-(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 时再次调用它。

关于ios - 迭代视频数组 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26321602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com