skip to Main Content

I want to make slider for my AVPlayer, I used AVPlayer because I want to stream a mp3 file from Firebase..

I tried:

var duration = player.currentItem.asset.duration

but that obviously doesn’t work 🙂

I read the documentation of AVPlayer but I don’t get it
There is seek function and I don’t know how that work
In AVAudioPlayer there is duration function which show that information, but in AVPlayer there is nothing like unfortunately…

2

Answers


  1. Chosen as BEST ANSWER

    I solved this.

    I used currentTime in previous answer to get currentTime and convert that into seconds using CMTimeGetSeconds function.

    But for get complete duration I just made a function getDuration:

    func getDuration() -> String {
        
        var duration = audioManager.player?.currentItem?.asset.duration
        var getDurationString = DateComponentsFormatter.positional.string(from:CMTimeGetSeconds(duration!))
        
        return getDurationString!
    }
    

    and just call that function into my Text view.


  2. Hope this will help you.

    player.currentTime
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search