如何按间隔顺序播放多个AVAudioPlayers

时间:2017-08-17 12:43:45

标签: swift timer avaudioplayer pause

如何在一个函数中添加两个以上的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等等,但我不知道如何正确使用它。

0 个答案:

没有答案