Thank you very much for your reply. I have a strong reference for the AVAudioPlayer.
@objc public func playRingtone() {
guard let isPlaying = audioPlayer?.isPlaying, !isPlaying else { return }
if isFirstTimePlay {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.audioPlayer?.play()
}
isFirstTimePlay = false
} else {
audioPlayer?.currentTime = 0
audioPlayer?.play()
}
}
This is my code which is working fine for old (iPhone 6s)and new iPhone (iPhone 12). When I reduce the delay to 0.1s, then it is working fully for new iPhone but not working for old iPhone (playing only 1 sec audio and stopped). The same behaviour is happening for new iPhone if I remove the delay completely. Even without having delay, from second call onwards when my object already alive after first call, the ringtone play properly. The issue is happening when object created and called the play method immediately in first call. Any idea?
Topic:
Media Technologies
SubTopic:
Audio
Tags: