I used the xuggle-xuggler5.4 in my app to add video and audio playing functionality, I have dig into google and found following snippet:
long duration = container.getDuration();
long target = new Double(duration * .50).longValue();
container.seekKeyFrame(0, target, 0, 0, IContainer.SEEK_FLAG_BYTE);
I don't know if this snippet is not correct, or my xuggle is wrong, or I am SICK (just kidding) but every thing looks fine. when i play the video it always start from the first (not the location i want).
I would be very happy if someone can help me Thanks
OK I got that ;)
I got the video duration and frame rate as below :
IStream stream = iContainerObj.getStream(i);
IStreamCoder coder = stream.getStreamCoder();
if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO
&& videoStreamId == -1) {
videoDuration = container.getDuration() == Global.NO_PTS ? 0
: container.getDuration() / 1000;
frameRate = coder.getFrameRate().getDouble();
// other ....
}
then to jump to the specific location, I convert the duration which was in milli second to second then multiplied to frameRate and the second i want. And finally called seekKeyFrame to jump to position.
int jumpToThisSecond = 65;
long jumbTo = (long) (((videoDuration / 1000) * frameRate) * jumpToThisSecond);
container.seekKeyFrame(0, 0, jumbTo, container.getDuration(),
IContainer.SEEK_FLAG_FRAME);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With