AVPlayer streaming progress

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

    This method will return buffer time interval for your UISlider

    public var bufferAvail: NSTimeInterval {
    
        // Check if there is a player instance
        if ((player.currentItem) != nil) {
    
            // Get current AVPlayerItem
            var item: AVPlayerItem = player.currentItem
            if (item.status == AVPlayerItemStatus.ReadyToPlay) {
    
                var timeRangeArray: NSArray = item.loadedTimeRanges
                var aTimeRange: CMTimeRange = timeRangeArray.objectAtIndex(0).CMTimeRangeValue
                var startTime = CMTimeGetSeconds(aTimeRange.start)
                var loadedDuration = CMTimeGetSeconds(aTimeRange.duration)
    
                return (NSTimeInterval)(startTime + loadedDuration);
            }
            else {
                return(CMTimeGetSeconds(kCMTimeInvalid))
            }
        } 
        else {
            return(CMTimeGetSeconds(kCMTimeInvalid))
        }
    }
    

提交回复
热议问题