我試圖播放兩個audioPlayers,一個接一個完成播放。我使用的夫特函數playAtTime()來創建用於所述第二延遲,如下所示:Swift函數playAtTime()不會添加延遲
var audioPlayer1 = AVAudioPlayer()
var audioPlayer2 = AVAudioPlayer()
let soundPathA = NSBundle.mainBundle().pathForResource("A", ofType: "m4a")
let soundURLA = NSURL.fileURLWithPath(soundPathA!)
let soundPathB = NSBundle.mainBundle().pathForResource("B", ofType: "m4a")
let soundURLB = NSURL.fileURLWithPath(soundPathB!)
var noteA = Sound()
noteA.URL = soundURLA
var noteB = Sound()
noteB.URL = soundURLB
self.audioPlayer1 = try!AVAudioPlayer(contentsOfURL: soundURLA)
self.audioPlayer2 = try!AVAudioPlayer(contentsOfURL: soundURLB)
let duration : NSTimeInterval = audioPlayer1.duration
self.audioPlayer1.play()
self.audioPlayer2.playAtTime(duration)
但是,沒有發生延遲。我的問題在這裏?
什麼是從'duration'返回的值? –
0.648707482993197 – Sunay
這隻會延遲約0.6秒,是你想要的延遲量? – MikeG