playing video in ios 6

2019-07-17 09:42发布

问题:

I wanted to play a video in ios 6. I am using Xcode 4.5. I write code below but getting error

 Test Demo[736:14003] [MPAVController] Autoplay: Disabling autoplay for pause
 Test Demo[736:14003] [MPAVController] Autoplay: Disabling autoplay
 Test Demo[736:14003] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)

and my code

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"TestVideo" ofType:@"m4v"];
NSURL *streamURL = [NSURL fileURLWithPath:videoPath];

MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: streamURL];
[player prepareToPlay];
[player.view setFrame: self.view.bounds];  // player's frame must match parent's
[self.view addSubview: player.view];
// ...
[player play];`

回答1:

There could be many issues for your error.

1) Set a property for your MPMoviePlayerController and synthesize it. This may occur, if your MPMoviePlayerController releases before it plays.

2) add this code player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

3) As per documentation, .m4v extension is not mentioned to play.

4) Below screenshot will help you about supported formats.



回答2:

NSString *url   =   [[NSBundle mainBundle] pathForResource:@"santaMessage" ofType:@"mp4"];

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];

[self.view addSubview:moviePlayer.view];

moviePlayer.fullscreen = YES;

moviePlayer.allowsAirPlay = YES;

[moviePlayer play];

///this worked like a charm