title: Audio not playing in SwiftUI
body: <p>I'm having an issue getting an audio file to play when the function is called.</p>
  
  <p>I am using an AVAudioPlayer to try and play the file following the instructions form here:
  <a href="https://www.hackingwithswift.com/example-code/media/how-to-play-sounds-using-avaudioplayer" rel="noreferrer">https://www.hackingwithswift.com/example-code/media/how-to-play-sounds-using-avaudioplayer</a>
  After the button is pressed in the view, it calls a func to play the sound, but from what I can tell, nothing is played. There are no errors thrown, and the file is found. The app also uses a speech synthesizer when a button is pushed, and that plays fine.</p>
  
  <p>I looked around stack overflow and followed the instructions from here:
  <a href="https://stackoverflow.com/questions/57068891/where-to-place-code-for-audio-playback-in-a-swiftui-app">Where to place code for audio playback in a SwiftUI app</a></p>
  
  <p>But still the audio is not played when the button is pushed.</p>
  
  <p>Here is the func:</p>
  
  <pre class="lang-swift prettyprint-override"><code>    func playSound() {
          var sound = AVAudioPlayer()
  
          if let path = Bundle.main.path(forResource: "TryAgain", ofType: "wav") {
              do {
                  sound = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
                  print("Playing sound")
                  sound.play()
              } catch {
                  print( "Could not find file")
              }
          }
  </code></pre>
  
  <p>Here is the class:</p>
  
  <pre class="lang-swift prettyprint-override"><code>class Player: BindableObject {
  
      let willChange = PassthroughSubject&lt;Player, Never&gt;()
  
      var isPlaying: Bool = false {
          willSet {
              willChange.send(self)
          }
      }
  
      func playSound() {
          var sound = AVAudioPlayer()
  
          if let path = Bundle.main.path(forResource: "TryAgainWav", ofType: "wav") {
              do {
                  sound = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
                  print("Playing sound")
                  sound.play()
              } catch {
                  print( "Could not find file")
              }
          }
      }
  }
  </code></pre>
  
  <p>Update: Not sure if this helps, but I built this in with IB instead of SwiftUI and noticed the same message is printed in the console when I click the button to play the audio file:</p>
  
  <p>2019-07-22 11:29:41.075568-0700 PlaySoundPrac[13952:46549155] [plugin] AddInstanceForFactory: No factory registered for id  F8BB1C28-BAE8-11D6-9C31-00039315CD46</p>
  
  <p>Any help would be greatly appreciated</p>