How can I ignore the system quantity in order that when an MP3 is performed and, for instance, the iPhone’s quantity is ready to five%, the AudioPlayer’s quantity is at all times at 100%?
Presently, the Audio Participant adjusts to the iPhone’s media quantity!
func playProgressTone() {
guard let soundURL = Bundle.principal.url(forResource: "ProgressTone", withExtension: "mp3") else {
print("Error: Audio file 'ProgressTone.mp3' not discovered.")
return
}
do {
progressTonePlayer = strive AVAudioPlayer(contentsOf: soundURL)
progressTonePlayer?.quantity = 5.0
progressTonePlayer?.numberOfLoops = -1 // Repeat till the decision is linked
// Delay of 1.0 seconds earlier than taking part in the sound
DispatchQueue.principal.asyncAfter(deadline: .now() + 0.5) { [weak progressTonePlayer] in
progressTonePlayer?.play()
print("Progress tone will play after 1 second.")
}
} catch let error as NSError {
print("Error taking part in the progress tone: (error.localizedDescription)")
}
}