0

When i try using AVURLAsset.init to an audio having url something similar below . Below url is example url.

https://web-web.test.net/media/abcdefghijklmnopqrst?sr=abcdefghijklmnopqrst

Calling audioAsset.statusOfValue() returns as .failed . Please let me know if any sugesions. Below is complete code i have written.

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
                    }
                })
            }
        }
nikhil
  • 616
  • 8
  • 22
  • Your url is not an url of audio file. You need to pass into `init` exact url of real audio file – Taras Chernyshenko Mar 07 '19 at 10:52
  • 1
    i think you need to setting mime_type with file extension something like that https://stackoverflow.com/questions/5501670/how-to-play-movie-files-with-no-file-extension-on-ios-with-mpmovieplayercontroll – Nitin Gohel Mar 07 '19 at 10:53
  • @TarasChernyshenko In above given Url its just a example(Dummy). I cannot share a url in stack overflow reason is its generated from server and expires after 10 minute. I have tried playing url in web it plays without any problem. – nikhil Mar 07 '19 at 11:24

0 Answers0