I am calling this function playSound()
in viewWillAppear
, the audio starts playing and then suddenly volume increases with a minor break in playback.
here is my code
func playSound() {
let url = Bundle.main.url(forResource: "music", withExtension: "mp3")!
do {
try self.player = AVAudioPlayer(contentsOf: url)
player?.prepareToPlay()
player?.numberOfLoops = -1
player?.play()
} catch let error as NSError {
KBLog.log(object: error.description)
}}
Edit 1 : I am using this code for an iPad app, so ipad only have speaker, no earpiece, if this has something to do with the issue.
The problem was i was playing this audio and at the same time i was initialising my publisher view for starting the video call, thus an instance of AVPlayer was initialised to take audio input i.e. two instances of AVPlayer were getting initialised causing the break in playback.