Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Audio duration returns nan in AVQueuePlayer

When I try to play a .wav file from server using AVQueuePlayer it returns duration as nan.

I used this code to get the duration

audioPlayer.currentItem?.duration.seconds 
audioPlayer.currentItem?.asset.duration.seconds

And I am sure that .wav file I am using is not corrupted since its being used by android app and they are able to get the duration.

Below code that I used works perfectly for .mp3. but not for .wav

if let url = URL(string: urlString) {
            audioAsset = AVURLAsset.init(url: url)

            if let audioAsset = audioAsset {

                let keys = ["playable"]

                   audioAsset.loadValuesAsynchronously(forKeys: keys, completionHandler: {

                    let playableStatus = audioAsset.statusOfValue(forKey: keys[0], error: nil)
                    switch playableStatus {

                    case .unknown,  .loading,  .failed,  .cancelled:
                        return

                    case .loaded:

                        DispatchQueue.main.async {

                            let playerItem = AVPlayerItem.init(asset: audioAsset)
                            self.audioPlayer.insert(playerItem, after: nil)
                            self.audioPlayer.play()

                            })
                        }
                        break
                    }
                })
            }
        }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!