如何在一个函数中添加两个以上的player
?就像拨号音一样,我需要将player
连成一排并在它们之间稍微停顿一下。这是我到目前为止所做的:
import UIKit
import AVFoundation
import CoreData
class FirstViewController: UIViewController {
var player:AVAudioPlayer?
var player2:AVAudioPlayer?
var player3:AVAudioPlayer?
var player4:AVAudioPlayer?
var secondSoundTimer: Timer?
@IBAction private func play(_ sender: Any) {
stopPlaying()
player?.play()
secondSoundTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) {timer in
self.player2?.play()
self.secondSoundTimer?.invalidate()
self.secondSoundTimer = nil
}
}
我尝试使用thirdSoundTimer
等等,但我不知道如何正确使用它。