ios - MPMoviePlayerViewController 不播放

标签 ios objective-c video-streaming mpmovieplayercontroller mpmoviewcontroller

我会保持简单,代码如下:

- (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 是一个 MPMoviePlayerViewController。 View Controller 出现了,但电影没有开始,它只是说“正在加载...”,在你问之前我100%确定链接有效。

谢谢!

最佳答案

它不起作用,因为主线程上未调用完成 block 。 您可以通过强制在主线程上执行代码来解决:

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

关于ios - MPMoviePlayerViewController 不播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15342609/

相关文章:

ios - fb ios sdk 4.8 同时分享图片和url

ios - 如何在 App 项目中使用 Cocoa Touch Frameworks

php - FFmpeg : why we need to create temp files during conversion

javascript - 使用 Jscript 在 Jw Player 中重新播放高清视频文件

iphone - Facebook 相当于 iOS 上的 TWTweetComposeViewController?

ios - 我们可以在 Swift 的 Enum 中使用初始值设定项吗?

ios - ionic native 文件保存文件后第一次无法读取文件

iOS 11 - 成为第一响应者不打开键盘

objective-c - 执行选择器 :withObject:afterDelay: not working in a NSPanel?

java - 如何在直播 Android 中播放视频之前显示进度条?