VLC player_KVO监听

#pragma mark - -- KVO监听
// 添加监听
- (void)addObserver
{
    // 监听VLC对象属性(时间和播放)
    [_player.player addObserver:self forKeyPath:@"remainingTime" options:0 context:nil];
    [_player.player addObserver:self forKeyPath:@"isPlaying" options:0 context:nil];
}
// kvo监听回调
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {

    // 可以在这里设置显示的时间和进度
    // position:VLCMediaPlayer对象中的进度比例,可用此值设置播放进度
    //    NSLog(@"[_player.player position]:%lf",[_player.player position]);
    // remainingTime:VLCMediaPlayer对象中的剩余时间,stringValue可以转化为时间格式字符串
    //    NSLog(@"[[_player.player remainingTime] stringValue]:%@",[[_player.player remainingTime] stringValue]);
    // time:VLCMediaPlayer对象中的当前时间
    //    NSLog(@"[[_player.player time] stringValue]:%@", [[_player.player time] stringValue]);

    //    NSLog(@"剩余的分钟:%@",[[_player.player remainingTime] minuteStringValue]);
    //    NSLog(@"播放的分钟:%@",[[_player.player time] minuteStringValue]);
    // 记录当前进度
    self.currentProgress = [_player.player position];
    // 根据分钟计算播放的秒数(这里不够严格,还得加上秒数)
    self.videoCurrentTime = [[[_player.player time] minuteStringValue] intValue] * 60;
    // 根据剩余时间和已经播放的计算总秒数(这里不够严格,还得加上秒数)  
    self.videoAllTime = [[[_player.player remainingTime] minuteStringValue] intValue]*60 + self.videoCurrentTime;

    // 有时候获取不到时间(个人想法是结合定时器和进度比例计算总时间等)
    // ...

    // 刷新最新时间和播放进度
    [self updateTime];
    // 停止菊花加载
    if (self.activityView.isAnimating) {
        [self.activityView stopAnimating];
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值