2014-10-12 5 views
0

У меня есть массив URL-адресов. Горизонтальная цель:Iterate Over Array of Videos iOS

  1. Добавить расширение на базовый URL-адрес, чтобы создать URL-адрес для определенного видео.

  2. Воспроизведение видео в MPMovieViewController с использованием YTViewExtractor.

  3. Повторите эти действия для следующего расширения URL в массиве, когда MPMovieFinishReasonPlaybackEnded = TRUE или при следующем нажатии кнопки

Это моя работа до сих пор:

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 проходит через каждое действие для всех участников ts в массиве, прежде чем перейти к следующему действию, содержащемуся в цикле.

То, что у меня есть, не дает желаемого результата, и я благодарен за любые отзывы или советы.

+0

Это очень узкий вопрос. Вероятно, в будущем это было бы не полезно? – Sirens

+0

Я не согласен с вами, и я не знаю, как это сделать в целом. Если у вас есть предложения по обеспечению большей ценности для других пользователей, я был бы рад редактировать. –

ответ

1

Поскольку воспроизведение фильма является асинхронным событием, ваш цикл будет проходить весь путь до того, как первый фильм едва начался (вероятно, раньше). Вам нужно поместить код в метод, который вы вызываете, когда фильм сделан, и использовать счетчик, чтобы отслеживать, какой 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 вызывается.