Unable to play video using MPMoviePlayerViewController

I created a new project with the following ViewController.m. When I launch the application, I see a field of expected origin / size (38, 100, 250, 163), but it is black and the video does not play. There is a strange conclusion in Xcode:

2012-08-23 15:36:45.559 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay for pause 2012-08-23 15:36:45.560 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay 2012-08-23 15:37:18.186 VideoTest1[11398:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0) 

Please note that video is converted using Videora iPhone Converter and plays normally in Xcode (so this is not a problem with the video); the video path is fine, because when I specify demo-iPhone1 (which does not exist), I get a nil exception. I tried in Simulator and on iPhone: always a black box. Any ideas?

 #import "ViewController.h" #import <MediaPlayer/MediaPlayer.h> @interface ViewController () @end @implementation ViewController - (void)moviePlaybackComplete:(NSNotification *)notification { MPMoviePlayerController *moviePlayerController = [notification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController]; [moviePlayerController.view removeFromSuperview]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSString *filepath = [[NSBundle mainBundle] pathForResource:@"demo-iPhone" ofType:@"mp4"]; NSURL *fileURL = [NSURL fileURLWithPath:filepath]; MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController]; [moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)]; [self.view addSubview:moviePlayerController.view]; [moviePlayerController play]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } @end 
+8
ios iphone video
source share
4 answers

I just solved a similar problem with this line of code. The player’s controllers are now displayed, and the video plays perfectly:

 @property (nonatomic, strong) MPMoviePlayerController *moviePlayer; // @synthesize moviePlayer = _moviePlayer; // [self.moviePlayer prepareToPlay]; 

Change to suit your environment.

+13
source share

I solve a similar problem by adding playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

+3
source share

Do you use ARC? If so, you need to save MPMoviePlayerController!

Add this to your interface

 @property (nonatomic, strong) MPMoviePlayerController *controller; 

Check last line of viewDidLoad

 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSString *filepath = [[NSBundle mainBundle] pathForResource:@"demo-iPhone" ofType:@"mp4"]; NSURL *fileURL = [NSURL fileURLWithPath:filepath]; MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController]; [moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)]; [self.view addSubview:moviePlayerController.view]; [moviePlayerController play]; [self setController:moviePlayerController]; } 
+2
source share

Also check the video format. I kept getting this error with my sample .m4v video (which I downloaded from the Apple website). In the end, I tried it with another video, which was .mp4 , and it worked fine. Many of the errors still appeared on my console.

 2013-01-22 15:44:04.850 VideoTesting[4497:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0 2013-01-22 15:44:04.851 VideoTesting[4497:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up. 2013-01-22 15:44:04.853 VideoTesting[4497:c07] [MPAVController] Autoplay: Disabling autoplay for pause 2013-01-22 15:44:04.853 VideoTesting[4497:c07] [MPAVController] Autoplay: Disabling autoplay 2013-01-22 15:44:04.861 VideoTesting[4497:c07] [MPAVController] Autoplay: Enabling autoplay 

However, the video was still playing.

-2
source share

All Articles