AVPlayer不会在iOS9中播放来自网址的视频

我试图在UIView中嵌入一个AVPlayer并从网址播放mp4视频文件.问题是我只收到一个黑色的空白视图(见截图)

在以前的iOS版本中,它对我有用,但自从升级到iOS9后我遇到了这个问题.

我的.h文件如下所示:

@interface ViewController : UIViewController
@property (strong,nonatomic) IBOutlet UIView *viewPlayerContainer;

而在我的实现文件中,我有以下内容

@import AVFoundation;
@import AVKit;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];

    NSURL *url = [NSURL URLWithString:@"http://techslides.com/demos/sample-videos/small.mp4"];

    AVURLAsset *asset = [AVURLAsset assetWithURL: url];
    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset];

    AVPlayer * player = [[AVPlayer alloc] initWithPlayerItem: item];

    [playerViewController.view setFrame:CGRectMake(0,_viewPlayerContainer.bounds.size.width,_viewPlayerContainer.bounds.size.width)];

    playerViewController.showsPlaybackControls = NO;

    [_viewPlayerContainer addSubview:playerViewController.view];


    [player play];


}

我错过了什么吗?

提前致谢!

解决方法

@implementation ViewController{
    AVPlayerViewController *playerViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
     playerViewController = [[AVPlayerViewController alloc] init];
}

- (IBAction)playVideo:(id)sender {
    NSURL *url = [NSURL URLWithString:@"http://techslides.com/demos/sample-videos/small.mp4"];

    AVURLAsset *asset = [AVURLAsset assetWithURL: url];
    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset];

    AVPlayer * player = [[AVPlayer alloc] initWithPlayerItem: item];
    playerViewController.player = player;
    [playerViewController.view setFrame:CGRectMake(0,self.view.bounds.size.width,self.view.bounds.size.width)];

    playerViewController.showsPlaybackControls = YES;

    [self.view addSubview:playerViewController.view];

    [player play];
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...