How to play mp3 audio from URL in ios swift

后端 未结 9 671
鱼传尺愫
鱼传尺愫 2020-11-30 04:50

I am getting mp3 url as a response of api calling. I want to play that audio, so how can i do that? (ios swift)

here is my response

 {
    content =          


        
9条回答
  •  隐瞒了意图╮
    2020-11-30 05:28

    To play a sound in swift2 is

    func playSound(soundUrl: String)
    {
       let sound = NSURL(soundUrl)
      do{
          let audioPlayer = try AVAudioPlayer(contentsOfURL: sound)
          audioPlayer.prepareToPlay()
          audioPlayer.play()
      }catch {
          print("Error..")
      }
    }
    

    Let me know if it working.

提交回复
热议问题