android seekto实现_Android IjkPlayer seekto后会有时会向后跳跃?不准确怎么解决

本文介绍了如何解决Android IjkPlayer在seekto后可能出现的向后跳跃问题,通过设置多个IjkMediaPlayer选项并实施重复seekto机制,确保视频定位的准确性。详细讲述了配置过程和监听seek完成的方法。
摘要由CSDN通过智能技术生成

我已经解决了,包括播放网络视频,而且运行的很好!!我发现一个规律,只要多次seekto 之后,肯定能准确跳转。所以我写了一个重复seekto 的机制:

首先初始化加入配置项:

//SeekTo设置优化

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0L);

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "fflags", "fastseek"); //快速seekto

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1);

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 0);

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32);

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1);

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0);

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", 1);

//重复seekto 的过渡值

private int curSeekPos = -1;

private int curSeekCount = 0;

mPlayerSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

@Override

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

if (!fromUser) {

return;

}

long duration = getDuration();

long newposition = (duration * progress) / 1000L;

seekTo((int) newposition);

if (mPlayerTime != null)

mPlayerTime.setText(stringForTime((int) newposition));

}

@Override

public void onStartTrackingTouch(SeekBar seekBar) {

curSeekPos = 0;

curSeekCount = 0;

}

@Override

public void onStopTrackingTouch(SeekBar seekBar) {

long duration = getDuration();

long newposition = (duration * seekBar.getProgress()) / 1000L;

if (mMediaPlayer != null && mMediaPlayer instanceof IjkMediaPlayer) {

((IjkMediaPlayer) mMediaPlayer).setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "seek-at-start", newposition);

}

seekTo((int) newposition);

//记录最后需要seekto 的position。

curSeekPos = (int) newposition;

}

});

//重复 seekto

private void repeatSeekTo() {

curSeekCount++;

if (mMediaPlayer != null && mMediaPlayer instanceof IjkMediaPlayer) {

((IjkMediaPlayer) mMediaPlayer).setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "seek-at-start", curSeekPos);

}

seekTo(curSeekPos);

}

// 监听是不是 seekto 成功了,不成功重seekto,最大次数为 3 次

private IMediaPlayer.OnSeekCompleteListener mSeekCompleteListener = new IMediaPlayer.OnSeekCompleteListener() {

@Override

public void onSeekComplete(IMediaPlayer mp) {

boolean isSeekComplete = true;

if (curSeekPos > 0) {

if (Math.abs(mMediaPlayer.getCurrentPosition() - curSeekPos) <= 1000) {

curSeekPos = 0;

curSeekCount = 0;

} else if (curSeekCount <= 3) {

repeatSeekTo();

isSeekComplete = false;

}

}

}

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值