playableDuration can be roughly implemented as follows:
- (NSTimeInterval) playableDuration { // use loadedTimeRanges to compute playableDuration. AVPlayerItem * item = _moviePlayer.currentItem; if (item.status == AVPlayerItemStatusReadyToPlay) { NSArray * timeRangeArray = item.loadedTimeRanges; CMTimeRange aTimeRange = [[timeRangeArray objectAtIndex:0] CMTimeRangeValue]; double startTime = CMTimeGetSeconds(aTimeRange.start); double loadedDuration = CMTimeGetSeconds(aTimeRange.duration); // FIXME: shoule we sum up all sections to have a total playable duration, // or we just use first section as whole? NSLog(@"get time range, its start is %f seconds, its duration is %f seconds.", startTime, loadedDuration); return (NSTimeInterval)(startTime + loadedDuration); } else { return(CMTimeGetSeconds(kCMTimeInvalid)); } }
_moviePlayer is your AVPlayer instance, by checking the downloaded AVPlayerItemTimeRanges file, you can calculate the estimated playableDuration.
For videos that have only 1 section, you can use this procedure; but for multi-section video, you can check all time ranges in an array of loaded TimeRagnes to get the correct answer.
John lingburg
source share