AVPlayer streaming progress

前端 未结 6 1398
死守一世寂寞
死守一世寂寞 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:15

    Selected answer may cause you problems if returned array is empty. Here's a fixed function:

    - (NSTimeInterval) availableDuration
    {
        NSArray *loadedTimeRanges = [[_player currentItem] loadedTimeRanges];
        if ([loadedTimeRanges count])
        {
            CMTimeRange timeRange = [[loadedTimeRanges objectAtIndex:0] CMTimeRangeValue];
            Float64 startSeconds = CMTimeGetSeconds(timeRange.start);
            Float64 durationSeconds = CMTimeGetSeconds(timeRange.duration);
            NSTimeInterval result = startSeconds + durationSeconds;
            return result;
        }
        return 0;
    }
    

提交回复
热议问题