AVplayer断网播放出错时player的duration、playableDuration、totalTime

使用系统的AVplayer做点播播放器,断网播放出错后player的duration和playableDuration获取不到,写了get方法获取不到时返回0,然后就掉坑里了。

获取播放时长的get方法

- (NSTimeInterval)duration {
        return isnan(vodPlay.hlsPlayer.duration)?0:vodPlay.hlsPlayer.duration;
    }
    return 0;
}

获取缓存进度的get方法

- (NSTimeInterval)playableDuration {
        return isnan(vodPlay.hlsPlayer.playableDuration)?0:vodPlay.hlsPlayer.playableDuration;
    }
    return 0;
}

因为返回了0,所以播放出错时,totalTime,导致进度条被重置到了0的位置,并没办法滑动。因为

    self.vodSlider.maximumValue = totalTime;
    self.vodSlider.minimumValue = 0.0;

设置了进度条的最大值是播放时长度,出错后maximumValue被设置成了0,就出现了进度条滑块被重置到0的位置,并无法滑动了的问题。

由于totalTime成了0,playableDuration也成了0,

[self.vodSlider.progressView setProgress:playable/totalTime animated:NO];

playable/totalTime分子分母都为0,导致了不可预知的问题,滑块的缓存进度值就会是个不确定的值,导致缓存显示出问题。

关于Slider

设置滑竿和时间的方法

- (void)setProgressTime:(CGFloat)currentTime totalTime:(CGFloat)totalTime playableValue:(CGFloat)playable
{
    if (!self.vodSlider.isDragging) {
        //总时长
        self.vodTotalTimeLabel.text = [VHPlayerSkinTool timeFormat:totalTime];
        //更新当前播放时间
        self.vodCurrentTimeLabel.text = [VHPlayerSkinTool timeFormat:currentTime];
        //全屏显示时间
        self.vodfullScreenTimeLabel.text = [NSString stringWithFormat:@"%@/%@",self.vodCurrentTimeLabel.text,self.vodTotalTimeLabel.text];
        // 更新slider
        self.vodSlider.maximumValue = totalTime;
        self.vodSlider.minimumValue = 0.0;
        self.vodSlider.value        = currentTime;
    }
    
    //更新缓存时长
    [self.vodSlider.progressView setProgress:playable/totalTime animated:NO];
}

改成

- (void)setProgressTime:(CGFloat)currentTime totalTime:(CGFloat)totalTime playableValue:(CGFloat)playable
{
    if (!self.vodSlider.isDragging && currentTime > 0 && totalTime > 0) {
        //总时长
        self.vodTotalTimeLabel.text = [VHPlayerSkinTool timeFormat:totalTime];
        //更新当前播放时间
        self.vodCurrentTimeLabel.text = [VHPlayerSkinTool timeFormat:currentTime];
        //全屏显示时间
        self.vodfullScreenTimeLabel.text = [NSString stringWithFormat:@"%@/%@",self.vodCurrentTimeLabel.text,self.vodTotalTimeLabel.text];
        // 更新slider
        self.vodSlider.maximumValue = totalTime;
        self.vodSlider.minimumValue = 0.0;
        self.vodSlider.value        = currentTime;
    }
    
    //NSLog(@"******* playable %f %f %f",playable,currentTime,totalTime);
    //更新缓存时长,播放出错时,播放器返回的playable和totalTime是0。
    if (playable > 0 && totalTime > 0) {
        [self.vodSlider.progressView setProgress:playable/totalTime animated:NO];
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Morris_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值