I am trying to make the xcode simulated iPhone play a wav audio file when one of 7 buttons from the UI interface are pressed. The code is the following:
import UIKit
import AudioToolbox
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func notePressed(_ sender: UIButton) { //7 buttons are associated with this IBAction, tagged from 1-7
if let soundURL = Bundle.main.url(forResource: "note1", withExtension: "wav") {
var mySound: SystemSoundID = 0
AudioServicesCreateSystemSoundID(soundURL as CFURL, &mySound)
//play
AudioServicesPlaySystemSound(mySound);
print(sender.tag) //to print the button tag and make sure the IBAction is working
}
else{
print("no note")
}
}
}
When I run it, I see no errors. Also, when I press one of the 7 buttons, the button tag is indeed printed. The "no note" condition from the else statement is never printed.
There is a picture of the simulated iPhone running here. In the picture, each colored rectangle is one of the 7 buttons. They were pressed in a sequence so the tags can be seen printed in the output. Also, the "note1.wav" file can be seen in the navigation pain, in the Sound Files folder. If I click in note1.wav in the navigation pane, I can hear it just fine.
Here are the mac specs:
- Dual Core Processor
- 8GB of RAM
- macOS High Sierra 10.13.6
Also, I am using this mac through a remote desktop connection; this computer is from Macincloud, a remote mac rental service). I have no idea if this could change anything, but as I said before, I can hear audio files from the mac just fine if they are played out of the xcode device simulation.
Does anyone have any idea how to solve this?