【Android】 修复ijkPlayer进行m3u8 hls流播放时seek进度条拖动不准确的问题
项目中使用的播放器是ijkPlayer,发现播放切片特点的hls流(m3u8格式的视频)拖动seekBar的时候会莫名的跳转或者seek不到准确的位置,发现网友也遇到了同样的问题,ijk的开发者也说明了是因为UI层的问题导致的,需要自己排查。涉及到该问题的链接:
通过ijkPlayer播放m3u8视频时快进不准确的解决方案
为什么Sample里面的进度条,往前拖动进度条后,还会往后退几秒
向前拖动,进度条会往回跳
https://github.com/Bilibili/ijkplayer/issues/313
**bbcallen **commented on Jul 8, 2015
UI部分seekbar的回调处理得不太合理,如果放手很快,最后一个位置不会被传给播放器,建议自行修改。
既然开发者都说了,那么就老实分析代码吧。因为项目中用到的MediaController
继承自Android系统的MediaController
,所以还得看看源码,分析得出系统中实现是将seek的listener监听器放在onProgressChanged
这个方法中,这也是为什么我们断断续续拖动的时候播放器也会播放,知道这点就够了,把onProgressChanged
中的mPlayer.seekTo((int) newposition);
放到onStopTrackingTouch
方法中。
执行顺序是:
onStartTrackingTouch(执行一次) —> onProgressChanged(拖动就会不停的执行) —> onStopTrackingTouch(停止后最后执行一次)
实现代码如下:
public class CustomMediaController extends MediaController implements ICustomMediaController {
// ....................代码省略.............................
// There are two scenarios that can trigger the seekbar listener to trigger:
//
// The first is the user using the touchpad to adjust the posititon of the
// seekbar's thumb. In this case onStartTrackingTouch is called followed by
// a number of onProgressChanged notifications, concluded by onStopTrackingTouch.
// We're setting the field "mDragging" to true for the duration of the dragging
// session to avoid jumps in the position in case of ongoing playback.
//
// The second scenario involves the user operating the scroll ball, in this
// case there WON'T BE onStartTrackingTouch/onStopTrackingTouch notifications,
// we will simply apply the updated position without suspending regular updates.
private OnSeekBarChangeListener mSeekListener=new OnSeekBarChangeListener(){
long newposition;
public void onStartTrackingTouch(SeekBar bar){
show(3600000);
mDragging=true;
if(seekerBarDraggingListener!=null)
seekerBarDraggingListener.getCurrentDraggingstatus(mDragging);
// By removing these pending progress messages we make sure
// that a) we won't update the progress while the user adjusts
// the seekbar and b) once the user is done dragging the thumb
// we will post one of these messages to the queue again and
// this ensures that there will be exactly one message queued up.
mHandler.removeMessages(SHOW_PROGRESS);
}
public void onProgressChanged(SeekBar bar,int progress,boolean fromuser){
if(!fromuser){
// We're not interested in programmatically generated changes to
// the progress bar's position.
return;
}
long duration=mPlayer.getDuration();
newposition=(duration*progress)/1000L;
// 系统原来的实现是在progress改变的时候时刻都在进行videoplayer的seek
//这会导致seek m3u8切片文件的时候拖动seek时不准确,所以需要在拖动完成后才进行播放器的seekTo()
// mPlayer.seekTo((int) newposition);
if(mCurrentTime!=null)
mCurrentTime.setText(stringForTime((int)newposition));
}
public void onStopTrackingTouch(SeekBar bar){
mDragging=false;
mPlayer.seekTo((int)newposition);
if(seekerBarDraggingListener!=null)
seekerBarDraggingListener.getCurrentDraggingstatus(mDragging);
setProgress();
updatePausePlay();
if(isntNeedStayShowAfterDrag){
show(sDefaultTimeout);
// Ensure that progress is properly updated in the future,
// the call to show() does not guarantee this because it is a
// no-op if we are already showing.
mHandler.sendEmptyMessage(SHOW_PROGRESS);
}
}
};
// ....................代码省略.............................
}
【Android】 修复ijkPlayer进行m3u8 hls流播放时seek进度条拖动不准确的问题的更多相关文章
- android97 播放音频 有进度条控制
package com.itheima.musicplayer; import android.os.Bundle; import android.os.Handler; import android ...
- 03 SeekBar 音频播放拖拽进度条
八, SeekBar 音频播放拖拽进度条 > android:progress="40" 第一进度 and ...
- Android View 之进度条+拖动条+星级评论条....
PS:将来的你会感谢现在奋斗的自己.... 学习内容: 1.进度条 2.拖动条 3.星级评论条 1.进度条... 进图条这东西想必大家是很熟悉的...为了使用户不会觉得应用程序死掉了,因此 ...
- Android中ProgressBar的使用-通过Handler与Message实现进度条显示
场景 进度条效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改为 ...
- EasyNVR网页/微信播放RTSP摄像机HLS/RTMP播放时出现起播等待问题的优化过程
EasyNVR 项目中, 我们需要在网页/微信中嵌入 HLS 播放器, 实现直播效果. 开发过程中, 我们调研了很多HLS播放器, 包括 百度cyberplayer, ckplayer, flowpl ...
- Android——音乐播放器完善——进度条显示当前播放进度,加可拖动进度条(未待解决完问题)
效果: 问题:可拖动进度条随进度条移动时,会致使音乐卡顿(待解决) xml <?xml version="1.0" encoding="utf-8"?&g ...
- Android开发(24)---安卓中实现多线程下载(带进度条和百分比)
当我们学完java中多线程的下载后,可以将它移植到我们的安卓中来,下面是具体实现源码: DownActivity.java package com.example.downloads; import ...
- Android——对话框1(一般、选择、自定义、进度条)
xml <Button android:layout_width="match_parent" android:layout_height="wrap_conten ...
- qml 音乐播放器的进度条
进度条采用qml的Slider组件 样式什么的,网上很多.我就不列举了.接下来主要说明,进度条是怎样按秒移动的. Slider { id: control value: 0 stepSize: ...
随机推荐
- SSH实战 · 唯唯乐购项目(中)
用户模块 三:一级分类的查询 创建一级分类表并导入基本数据 CREATE TABLE `category` ( `cid` int(11) NOT NULL AUTO_INCREMENT, ` ...
- TODO:Laravel 内置简单登录
TODO:Laravel 内置简单登录 1. 激活Laravel的Auth系统Laravel 利用 PHP 的新特性 trait 内置了非常完善好用的简单用户登录注册功能,适合一些不需要复杂用户权限管 ...
- 前端学HTTP之日志记录
前面的话 几乎所有的服务器和代理都会记录下它们所处理的HTTP事务摘要.这么做出于一系列的原因:跟踪使用情况.安全性.计费.错误检测等等.本文将谥介绍日志记录 记录内容 大多数情况下,日志的记录出于两 ...
- Yeoman 官网教学案例:使用 Yeoman 构建 WebApp
STEP 1:设置开发环境 与yeoman的所有交互都是通过命令行.Mac系统使用terminal.app,Linux系统使用shell,windows系统可以使用cmder/PowerShell/c ...
- dagger2系列之依赖方式dependencies、包含方式(从属方式)SubComponent
本篇是实战文章,从代码的角度分析这两种方式.本文参考自下列文章: http://www.jianshu.com/p/1d42d2e6f4a5 http://www.jianshu.com/p/94d4 ...
- C#反序列化XML异常:在 XML文档(0, 0)中有一个错误“缺少根元素”
Q: 在反序列化 Xml 字符串为 Xml 对象时,抛出如下异常. 即在 XML文档(0, 0)中有一个错误:缺少根元素. A: 首先看下代码: StringBuilder sb = new Stri ...
- C# 索引器,实现IEnumerable接口的GetEnumerator()方法
当自定义类需要实现索引时,可以在类中实现索引器. 用Table作为例子,Table由多个Row组成,Row由多个Cell组成, 我们需要实现自定义的table[0],row[0] 索引器定义格式为 [ ...
- Html.DropDownLis绑定数据库
效果: 方法一: View: <div class="col-md-md-4"> <div class="input-group"> & ...
- H3 BPM让天下没有难用的流程之技术体系
一.技术架构 H3 BPM 基于微软.NET 技术架构,采用C#语言开发,以高开放.高扩展.高性能为核心准则,遵循分层的设计原理,结合最新的B/S 以及智能手机应用开发技术研发的. 图:H3 BPM ...
- Git使用详细教程(二)
分支 其实在项目clone下来后就有一个分支,叫做master分支.新建分支的步骤:右键项目→Git→Repository...→Branches... master分支应该是最稳定的,开发的时候,建 ...