1
AVAudioPlayer의 pause() 함수에서 예기치 않은 동작이 나타납니다. 'Pause'버튼을 클릭하면 오디오는 현재 시간에 일시 정지하고 play()가 호출되면 다시 시작됩니다. 그러나 여기에서 pause()를 누르면 오디오가 일시 중지되고 play()를 클릭하면 오디오가 처음부터 재생됩니다. pause()는 stop()과 같이 작동합니다.AVAudioPlayer pause()가 예상대로 작동하지 않습니다.
var player: AVAudioPlayer = AVAudioPlayer()
@IBAction func PlayPauseAudioButton(_ sender: UIButton) {
if sender.currentImage == #imageLiteral(resourceName: "play-btn") {
sender.setImage(#imageLiteral(resourceName: "pause-btn"), for: .normal)
do {
let audioPath = Bundle.main.path(forResource: "aug-ps-raj", ofType: "mp3")
try player = AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: audioPath!) as URL)
} catch {
// Catch the error
}
player.play()
} else {
sender.setImage(#imageLiteral(resourceName: "play-btn"), for: .normal)
player.pause()
}
}