在iPhone App中,MPMoviePlayerController以反向(向后)播放电影并不流畅 [英] MPMoviePlayerController playing movies in reverse (backwards) is not smooth in iPhone App
问题描述
我正在开发一个iPhone应用程序,我需要反转视频播放。我目前正在使用XCode 4.2。我正在尝试使用MPMoviePlayerController反向播放电影。
但是当它反向播放时,它并不像播放它那样顺畅。它变得有点波涛汹涌,并不是一帆风顺。以下是我的代码。
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?
推荐答案
我试图在AVFoundation中做同样的事情。在我设法让它工作之前,我必须工作很多。
I tried to do the same in AVFoundation. I had to work it quite a lot before I managed to get it to work.
我所做的是生成图像,颠倒顺序,将它们放入assetWriter,导出视频然后播放。
What I did was to generate image, reverse the order, put them in to an assetWriter, export the video and then play it.
您可以在此处下载我的代码: https://github.com/mikaelhellqvist/ReverseClip
You can download my code here: https://github.com/mikaelhellqvist/ReverseClip
这篇关于在iPhone App中,MPMoviePlayerController以反向(向后)播放电影并不流畅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!