I used MPMoviePlayer to play a short video in my application without any problems in SDK 3.1.3. I made changes to the SDK 4 code, but the video does not play. I just get a black screen and sound. Apple Dev Center does not have sample code for this class for the latest SDK. The following is the code I'm using:
- (void)viewDidLoad {
[super viewDidLoad];
if (videoPlayer == nil){
NSString * videoPath = [[NSBundle mainBundle] pathForResource:@"myvideo" ofType:@"mp4"];
if (videoPath == NULL){
return;
}
NSURL * videoURL = [NSURL fileURLWithPath:videoPath];
videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
videoPlayer.controlStyle = MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:@"MPMoviePlayerPlaybackDidFinishNotification" object:movieController.moviePlayer];
[videoPlayer play];
[videoPlayer setFullscreen:YES];
[self.view addSubview:videoPlayer.view];
}
}
The above leads to simple reproduction of sound using a black screen. The notification is triggered correctly at the end of playback.
If the above didn't work, I even tried using the new MPMoviePlayerViewController class as follows:
- (void)viewDidLoad {
[super viewDidLoad];
NSString * videoPath = [[NSBundle mainBundle] pathForResource:@"myvideo" ofType:@"mp4"];
if (videoPath == NULL){
return;
}
NSURL * videoURL = [NSURL fileURLWithPath:videoPath];
movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:@"MPMoviePlayerPlaybackDidFinishNotification" object:movieController.moviePlayer];
[movieController.moviePlayer setFullscreen:YES];
[movieController.moviePlayer play];
[self presentMoviePlayerViewControllerAnimated:movieController];
}
The same problem persists - I hear that the sound and notification at the end of playback are called as expected. However, I just see a black screen instead of a video.
, iTunes, iPod Touch .
- ?