swift 用于在swift 4中播放文件音频的配方

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 用于在swift 4中播放文件音频的配方相关的知识,希望对你有一定的参考价值。

// initialise audioPlayer of type AVAudioPlayer with !bang (as class member)
var audioPlayer: AVAudioPlayer!


// ACTION
    // create soundUrl with Bundle.main.url()  filename                 extension
   let soundUrl = Bundle.main.url(forResource: "note1", withExtension: "wav")
          
    do {
        // try to instantiate new instance of AVAudioPlayer with contentsOf: soundUrl! (!bang)
        audioPlayer = try AVAudioPlayer(contentsOf: soundUrl!)
    } catch  {
        print(error)
    }
    // Play it.
    audioPlayer.play()
        
    
  

}

以上是关于swift 用于在swift 4中播放文件音频的配方的主要内容,如果未能解决你的问题,请参考以下文章