OSStatus error 2003334207 when using AVAudioPlayer

前端 未结 7 1246
野的像风
野的像风 2021-01-17 13:10

I am trying to play an MP3 file (works when played via VLC/iTunes) when a button is pressed. Here is my code:

     var audioPlayer: AVAudioPlayer!
     @IBAc         


        
7条回答
  •  天涯浪人
    2021-01-17 13:28

    try this one

    var player: AVAudioPlayer = AVAudioPlayer()
    
    
    @IBAction func playX(_ sender: Any) {
        let urlstring = "https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_700KB.mp3"
        let url = URL(string: urlstring)
        let data = try! Data(contentsOf: url!)
        player = try! AVAudioPlayer(data: data)
        player.prepareToPlay()
        player.volume = 1.0
        player.play()
    }
    

提交回复
热议问题