开发者

UIPanGesture Movie Control Laggy

I have an app that plays a video. I want to control the video by Gesture i.e. left-to-right for forwards and right-to-left for backwards.

I have been working with a UIPanGesture and it's allowing me to advance the video with a left/right pan gesture. The only issue is that it's very slow, and doesn't advance the video very often; despite my NSLog firing loads of times per second (depending on the speed and time of th开发者_如何学JAVAe gesture).

Here is my code for the gesture handler:

- (void) handlePanGesture:(UIPanGestureRecognizer*)pan{

    CGPoint translate = [pan translationInView:self.view];
    CGFloat xCoord = translate.x;
    double diff = (xCoord - currentTranslate);
    currentTranslate = xCoord;
    NSLog(@"%F",diff);

    if (diff>=0) {
        //If the difference is positive
        moviePlayer.currentPlaybackTime = [moviePlayer currentPlaybackTime] + (diff/10);
    } else {
        //If the difference is negative
        moviePlayer.currentPlaybackTime = [moviePlayer currentPlaybackTime] - (diff/10);
    }
}

I'm not sure where to go from here now, how do I make this function smooth and control the playhead in a less laggy manner?


First of all, use FFMPEG for encoding the video files. From my experience, its results are superior to any other solution (a fact that I thought was bizarre).

When it comes to seeking, make sure the GOP-length of your encodings is not set too high. A large GOP makes encoding more efficient but also makes seeking hard for the decoder. In other words, the more I-frames your encodings have, the smoother you will be able to seek around.

For some general parameters on encoding video's for use on an iPhone, see the ffmpeg cheat sheet by Rodrigo Polo.

For some details on the mighty power of FFMPEGs parameters when encoding H264, see the libx264 mapping and options guide.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜