문제

I'll keep it simple, heres the code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
VideoEntry *entry = [videoEntries objectAtIndex:indexPath.row];

[HCYoutubeParser h264videosWithYoutubeURL:[NSURL URLWithString:entry.url] completeBlock:^(NSDictionary *videoDictionary, NSError *error) {
    NSArray *urls = [videoDictionary allValues];
    NSURL *url = [NSURL URLWithString:[urls objectAtIndex:0]];
    [mp.moviePlayer setAllowsAirPlay:YES];
    [mp.moviePlayer setContentURL:url];
    [mp.moviePlayer prepareToPlay];
    [mp.moviePlayer play];
    [self presentMoviePlayerViewControllerAnimated:mp];
}];

}

mp is a MPMoviePlayerViewController. The view controller is presented but then the movie doesn't start, it just says "Loading..." and before you ask I'm 100% sure the links work.

Thanks!

도움이 되었습니까?

해결책

It doesn't work because the completion block isn't called on the main thread. You can solve by force the execution of your code on the main thread:

[HCYoutubeParser h264videosWithYoutubeURL:[NSURL URLWithString:entry.url]
                            completeBlock:^(NSDictionary *videoDictionary, NSError *error) {
    dispatch_async(dispatch_get_main_queue(), ^(void) {
        NSArray *urls = [videoDictionary allValues];
        NSURL *url = [NSURL URLWithString:[urls objectAtIndex:0]];
        [mp.moviePlayer setAllowsAirPlay:YES];
        [mp.moviePlayer setContentURL:url];
        [mp.moviePlayer prepareToPlay];
        [mp.moviePlayer play];
        [self presentMoviePlayerViewControllerAnimated:mp];
    });
}];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top