Using AudioKit for sound management, I noticed an issue (bug?) with this very simple piece of code.
import AudioKit
class MainViewController: UIViewController {
var audioFile: AKAudioFile?
var audioPlayer: AKAudioPlayer?
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func onPlayButtonClick(_ sender: Any) {
do {
audioFile = try AKAudioFile(forReading: Bundle.main.url(forResource: "3e", withExtension: "mp3")!)
audioPlayer = try AKAudioPlayer(file: audioFile!)
AudioKit.output = audioPlayer
AudioKit.start()
audioPlayer!.play()
} catch {
print(error)
}
}
}
When launching the playback with play() method, everything is normal in logs and in the process (player duration, currentTime). BUT I do not hear the audio in speakers (only a kind of wind noise). As soon as I plug my headphones and tap the button again, I normally hear the audio. Then, I unplug my headphones and tap the button, I don’t hear audio (only that wind noise).
I face this on iPhone 5S.
I do not face this on iPad5, I do not face this on simulators. I don’t have the other devices to try to reproduce.
Both devices: iOS 11.1.2 and AudioKit : v4.0.4
NB: my speakers works normally with any other app and I’ve checked the volume. The default outputDevice is set to Speakers when headphones are not plugged.