前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >笔记86 | 视频在ACC起来后会跳进度问题分析

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

作者头像
项勇
发布2019-03-06 15:05:19
7990
发布2019-03-06 15:05:19
举报
文章被收录于专栏:项勇项勇项勇
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模块出问题外,想不到其他出问题的地方,这个问题我会持续会跟进中。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-02-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 项勇 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Author:li_xingwang
  • Author:xiangyong
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档