笔记86 | 视频在ACC起来后会跳进度问题分析

Author:li_xingwang

通过打印分析得到如下结论:
1.断ACC之后保存有进度到

    private void save() {
       if(isPlaying()) mCurrentPos =  mVideoView.getCurrentPosition();
       try {
           BufferedWriter bw = null;
           try {
               bw = new BufferedWriter(new  FileWriter("/data/tw/video"));
               bw.write(mCurrentAPath);
               bw.write('\n');
               bw.write(Integer.toString(mCurrentIndex));
               bw.write('\n');
               bw.write(Integer.toString(mCurrentPos));
               bw.write('\n');
               bw.write(Integer.toString(mCurrentType));
               bw.write('\n');
               bw.flush();
           } catch (Exception e) {
               new  File("/data/tw/video").delete();
           } finally {
               if(bw != null) {
                  bw.close();
                  bw = null;
               }
           }
           FileUtils.setPermissions("/data/tw/video",  0666, -1, -1);
       } catch (Exception e) {
       }
    }

2.ACC起来后,读取保存的进度并且播放

private void resume() {
        try {
           BufferedReader br = null;
           try {
               br = new BufferedReader(new  FileReader("/data/tw/video"));
               mCurrentAPath =  br.readLine();
               mCurrentIndex =  Integer.valueOf(br.readLine());
               mCurrentPos =  Integer.valueOf(br.readLine());
               mCurrentType =  Integer.valueOf(br.readLine());
           } catch (Exception e) {
           } finally {
               if(br != null) {
                  br.close();
                  br = null;
               }
           }
       } catch (Exception e) {
       }
        if(mCurrentAPath != null) {
            mCurrentPath =  mCurrentAPath.substring(0,  mCurrentAPath.lastIndexOf("/"));
        }
    }

3.进度条前面1~2秒是正常的,是根据保存的进度继续往前走,可是突然进度就倒退了,这必然是Handler里面处理进度条的地方导致的

4.getCurrentPosition这个方法里面获取的进度是通过mMediaPlayer获取的,所以应该是系统导致的问题,暂时还没想到好的解决办法

public int getCurrentPosition() {
        if (isInPlaybackState()) {
            return  mMediaPlayer.getCurrentPosition();
        }
        return mSeekWhenPrepared;
    }

Author:xiangyong

补充一下,我们发现ACC起来后,video会自动播放的,但经过打印可发现,Video在播放过程中handler会收到热拔插的信息,
而热拔插中有这么个方法

if((mCurrentPath != null) && mCurrentPath.startsWith(volume)) {
						if(msg.arg2 == 0) { //如果是拔出设备
							mPlaylistRecord.clearRecord();
							stop(); 
						} else {
							loadFile(mPlaylistRecord, mCurrentPath);
							if(mTW.getService() == TWVideo.ACTIVITY_RUSEME) { //之前有退回的问题
									current(mCurrentPos, false);
							}
						}
					}

符合条件会再次走current方法,而mCurrentPos又不是实时储存的,所以此处会导致进度跳的问题,
所以
1.mCurrentPos实时存储

 case SHOW_PROGRESS:  //获取到播放 更新播放时间进度等状态
		if(isPlaying()) {
			int duration = mVideoView.getDuration();
			int position = mVideoView.getCurrentPosition();
			mCurrentPos = mVideoView.getCurrentPosition(); //实时储存
                  ...

2.此处加一个判断条件

if((mTW.getService() == TWVideo.ACTIVITY_RUSEME)&&(!isPlaying())) { //之前有退回的问题
		current(mCurrentPos, false);
}

基本就解决了ACC起来跳秒问题

但但但是,有客户测试到ACC起来后播了十几秒后又回退起始位置播放,这太恐怖了,完全不在我的认知范围,除了底层Playmedia模块出问题外,想不到其他出问题的地方,这个问题我会持续会跟进中。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值