Hi all, I'm trying to get a MPMoviePlayer to work with multiple videos.
I can get an observer on my videoPlayer, and find if end of a video has reached by using:
But it's not very nice this way, because the movieplayer will dismiss and get back again straight away with the next video. I'm not sure how to play the next video, should I just dismiss the current videoPlayer and load up next one?
Besides that, it seems I can't get the next and previous track buttons to work.
Is there any way to setup a 'queue' of videos.
Anyone can help me in the right direction?
Currently got AVPlayer to work
However I can only get it in a view, not present it on its own like you can do with the MPMoviePlayer
Any help?
I can get an observer on my videoPlayer, and find if end of a video has reached by using:
Code:
- (void)MPMoviePlayerPlaybackStateDidChange:(NSNotification*)aNotification {
if(videoPlayer.moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
NSLog(@"Playing");
} else if(videoPlayer.moviePlayer.playbackState == MPMoviePlaybackStatePaused) {
NSLog(@"Paused");
} else if(videoPlayer.moviePlayer.playbackState == MPMoviePlaybackStateSeekingBackward) {
NSLog(@"Backward");
} else if(videoPlayer.moviePlayer.playbackState == MPMoviePlaybackStateSeekingForward) {
NSLog(@"Forward");
} else if(videoPlayer.moviePlayer.playbackState == MPMoviePlaybackStateStopped) {
NSLog(@"Stopped");
BOOL playbackEnded = ([[[aNotification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue] == MPMovieFinishReasonPlaybackEnded);
BOOL endReached = (videoPlayer.moviePlayer.currentPlaybackTime == videoPlayer.moviePlayer.playableDuration);
if (playbackEnded && endReached) {
if(playVideo < videos.count - 1) {
playVideo++;
NSURL *video = [self grabFileURL:[videos objectAtIndex: playVideo] fileType:@"mp4"];
videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:video];
[videoPlayer.moviePlayer prepareToPlay];
[videoPlayer.moviePlayer play];
[self dismissViewControllerAnimated:NO completion:nil];
[self presentMoviePlayerViewControllerAnimated: videoPlayer];
}
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:videoPlayer.moviePlayer];
[self dismissViewControllerAnimated:YES completion:nil];
}
} else if(videoPlayer.moviePlayer.playbackState == MPMoviePlaybackStateInterrupted) {
NSLog(@"Interupted");
}
}
But it's not very nice this way, because the movieplayer will dismiss and get back again straight away with the next video. I'm not sure how to play the next video, should I just dismiss the current videoPlayer and load up next one?
Besides that, it seems I can't get the next and previous track buttons to work.
Is there any way to setup a 'queue' of videos.
Anyone can help me in the right direction?
Currently got AVPlayer to work
Code:
AVPlayerItem *firstVideoItem = [AVPlayerItem playerItemWithURL: [self grabFileURL:@"vid1" fileType:@"mp4"]];
AVPlayerItem *secondVideoItem = [AVPlayerItem playerItemWithURL:[self grabFileURL:@"vid2" fileType:@"mp4"]];
AVPlayerItem *thirdVideoItem = [AVPlayerItem playerItemWithURL:[self grabFileURL:@"vid3" fileType:@"mp4"]];
queuePlayer = [AVQueuePlayer queuePlayerWithItems:[NSArray arrayWithObjects:firstVideoItem, secondVideoItem, thirdVideoItem, nil]];
AVPlayerLayer *theLayer = [AVPlayerLayer playerLayerWithPlayer: queuePlayer];
theLayer.frame = self.view.frame;
[self.view.layer addSublayer: theLayer];
[queuePlayer play];
However I can only get it in a view, not present it on its own like you can do with the MPMoviePlayer
Any help?
Last edited: