2014-10-26 34 views
3
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init]; 
playerViewController.player = [AVPlayer playerWithURL:[[NSBundle mainBundle] 
                 URLForResource:@"Besan" 
                 withExtension:@"mp4"]]; 
[playerViewController.player play]; 

我想在iOS 8中使用AVPlayerViewController,但視頻不加載。我只是獲得下面的屏幕。AVPlayer沒有加載視頻在iOS 8

整個代碼庫是在這裏https://github.com/sairamsankaran/AVPlayerDemo

enter image description here

+0

不知道爲什麼你沒有調試的URL – onmyway133 2015-01-20 09:21:51

回答

7

我下載完項目,並看看。解決方法非常簡單,您忘記將視頻文件包含在目標中,這意味着當您設置指向不存在的文件的URL時,這意味着NSURL爲零。

在Xcode的實用工具欄中,選擇導航器中的mp4文件,選擇文件檢查器,然後在「目標成員」中確保檢查您的應用目標。

一旦你做這個電影的推出將發揮。

+0

真棒。完美地工作 – 2014-10-27 02:11:04

0

@runmad,我也用同樣的方式做,但我試圖打開本地video.here是我的代碼

{ 
// Initialize the movie player view controller with a video URL string 
     AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init]; 
     /*NSURL *url = [NSURL URLWithString:@"https://www.youtube.com/watch?v=qcI2_v7Vj2U"]; 
     playerViewController.player = [AVPlayer playerWithURL:url];*/ 
//  playerViewController.player = [AVPlayer playerWithURL: [ [filePath]URLForResource:@"Besan" 
//                withExtension:@"mp4"]]; 
     NSLog(@"\nFile URL\n%@",videosURL); 
     AVPlayerItem* item=[[AVPlayerItem alloc]initWithURL:videosURL]; 
     NSLog(@"\n\nAVPlayerItem\n%@",item); 
     playerViewController.player=[AVPlayer playerWithPlayerItem:item]; 
     [playerViewController.player play]; 
     [self presentViewController:playerViewController animated:YES completion:^{}]; 
} 

我已經沒有AVPlayerItem完成,但結果是一樣的(只有黑色屏幕完成,播放,前進,後退按鈕)。

比我用MPMoviePlayerController嘗試,但它很快被駁回,不顯示視頻。 這裏的MPMoviePlayerController代碼,

{ 
    MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:videosURL]; 
     [self presentMoviePlayerViewControllerAnimated:moviePlayerController]; 
     [moviePlayerController.moviePlayer play]; 
} 
1

你可能會更好開始工作的例子和延伸的。如果你願意的話,你可以嘗試一個在我的blog post中描述的github中使用AVPlayerViewController的工作xcode示例項目,這是一個示例項目,顯示了Sun的高清SDO視頻,它看起來最好用於新視網膜iPad,因爲視頻是非常高的質量。