How to show buffered data on UISlider using MpMoviePlayerController in iOS?

后端 未结 3 1363
小蘑菇
小蘑菇 2021-01-31 06:24

I am using MPMoviePlayerController to play audio and I want to show the buffered data on slider like this ...

3条回答
  •  抹茶落季
    2021-01-31 07:02

    According the documentation of MPMoviePlayerController (available here) you can use the playableDuration property to retrieve the duration that has been loaded by the player.

    You would then have to subclass UISlider to draw the red part of your control in the drawRect: method.

    As for AVPlayer you would call loadedTimeRanges (documentation here) on the AVPlayerItem representing your content. That would give you an array of (as of iOS 8) a single CMTimeRange representing the part of your media that has been buffered. I would advise using [NSArray firstObject] when retrieving the time range to protect your code against a possibly empty array.

提交回复
热议问题