AVPlayer streaming progress

前端 未结 6 1406
死守一世寂寞
死守一世寂寞 2020-11-30 17:42

I\'m successfully using AVPlayer to stream audio from a server and what I want to do now is to show a custom UISlider who shows the progress of the

6条回答
  •  囚心锁ツ
    2020-11-30 18:23

    The code from Suresh Kansujiya in Objective C

    NSTimeInterval bufferAvail;
    
    if (player.currentItem != nil) {
    
        AVPlayerItem *item = player.currentItem;
        if (item.status == AVPlayerStatusReadyToPlay) {
            NSArray *timeRangeArray = item.loadedTimeRanges;
            CMTimeRange aTimeRange = [[timeRangeArray objectAtIndex:0] CMTimeRangeValue];
            Float64 startTime = CMTimeGetSeconds(aTimeRange.start);
            Float64 loadedDuration = CMTimeGetSeconds(aTimeRange.duration);
    
            bufferAvail = startTime + loadedDuration;
    
            NSLog(@"%@ - %f", [self class], bufferAvail);
        } else {
            NSLog(@"%@ - %f", [self class], CMTimeGetSeconds(kCMTimeInvalid)); }
    }
    else {
        NSLog(@"%@ - %f", [self class], CMTimeGetSeconds(kCMTimeInvalid));
    }
    

提交回复
热议问题