2017-05-04 88 views
0

下面的代碼是不工作AVPlayerViewController沒有顯示視頻

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

NSURL *url = [NSURL URLWithString:@"http://54.254.248.1/app/webroot/uploads/question_files/2017.04.20.13.43.45video.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, 0, self.view.bounds.size.width, self.view.bounds.size.width)]; 

playerViewController.showsPlaybackControls = YES; 

[self.view addSubview:playerViewController.view]; 

[player play]; 

回答

0

我修改您的代碼像這樣它可以工作:

NSURL *url = [NSURL URLWithString:@"http://54.254.248.1/app/webroot/uploads/question_files/2017.04.20.13.43.45video.mp4"]; 
AVPlayer * player = [AVPlayer playerWithURL:url]; 

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

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

playerViewController.showsPlaybackControls = YES; 

[self.view addSubview:playerViewController.view]; 

[player play]; 

,瞭解更多有關AVPlayerViewController

+0

你的代碼仍然是不工作 –

+0

你有編譯和測試這個代碼嗎? // clips.vorwaerts-gmbh.de/big_buck_bunny.mp4' –

+0

一定的工作,但我不使用你的網址,我用'的https替換您的網址請用我的網址朋友 – liangju