MPMoviePlayerController playing movies in reverse

2019-02-11 05:37发布

问题:

I am developing an iPhone application where I need to reverse a video playback. I am currently using XCode 4.2. I am trying to play a movie in reverse with the MPMoviePlayerController. But when it plays in reverse it is not as smooth as playing it forward. It becomes a bit choppy and is not at all smooth. The following is my code.

- (void)viewDidLoad{
//code for initializing the movie player
MPMoviePlayerController videoPlayer = 
[[MPMoviePlayerController alloc] initWithContentURL:"URL"];
self.videoPlayer = videoPlayer;
[videoPlayer release];
self.videoPlayer.view.userInteractionEnabled = NO;
self.videoPlayer.initialPlaybackTime = -1;
self.videoPlayer.shouldAutoplay=NO;
[self.videoPlayer prepareToPlay];


//code for initializing the button 
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[button setTitle:@"Reverse" forState:UIControlStateNormal];

[button addTarget:self 
action:@selector(reverseMovie) forControlEvents:UIControlEventTouchDown];

button.frame = CGRectMake(0, 0, 50, 40);

[self.view addSubview:button];
}

-(void)reverseMovie{
[self.videoPlayer setCurrentPlaybackRate:-1.0];
}

What could be the possible solution to this?

回答1:

I tried to do the same in AVFoundation. I had to work it quite a lot before I managed to get it to work.

What I did was to generate image, reverse the order, put them in to an assetWriter, export the video and then play it.

You can download my code here: https://github.com/mikaelhellqvist/ReverseClip



回答2:

Try this with AVPlayer

 avPlayer.rate=-1.0f;

This will set the rate to -ve,hence playing the video in reverse smoothly. :)