AVPlayer does not load videos in iOS 8

AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = [AVPlayer playerWithURL:[[NSBundle mainBundle]
                                                       URLForResource:@"Besan"
                                                       withExtension:@"mp4"]];
[playerViewController.player play];

      

I'm trying to use AVPlayerViewController in iOS 8. But the video won't load. I just get the screen below.

The whole codebase is here https://github.com/sairamsankaran/AVPlayerDemo

enter image description here

+3


source to share


3 answers


I upload your project and have a look. The solution is quite simple, you forgot to include the video file in your target, which means that when you configure the url that you point to a file that doesn't exist, it means NSURL

zero.

In the Utilities sidebar in Xcode with your mp4 file selected in the navigator, select File Inspector and Target Membership be sure to check the Target Application.



Once you do this, your movie will play on startup.

+7


source


You might be better off starting with a working example and expanding on it. If you like you can try a working xcode example project that uses AVPlayerViewController in github described in my post, this is an example project that shows high resolution SDO video in the sun, it looks best on new iPad retina as the video is very high quality.



+1


source


@runmad, I did the same as well, but I am trying to open a local video. Here's my code

{
// 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:^{}];
}

      

I did without AVPlayerItem

, but the result is the same (only a black screen with buttons "done", "play", "forward", "back").

than i tried with help MPMoviePlayerController

but it soon quit without showing video. here is MPMoviePlayerController Code,

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

      

0


source







All Articles