如何快速从耳机左右移动声音?

时间:2016-02-02 00:46:33

标签: ios swift audio swift2 avfoundation

我正在为盲人做一个快速的应用程序,我只能在正确的耳机上播放声音,或者只在左边使用pan属性播放声音:

@IBAction func right(sender: UIButton) {
    player.pan = 1.0 //right headphone
}


@IBAction func left(sender: UIButton) {
    player.pan = -1.0 //left headphone

}

但我需要开始播放右边的声音,然后将其移至左耳机,我该怎么做?

1 个答案:

答案 0 :(得分:2)

我不知道平移应该基于什么,但如果您只是希望它随着时间的推移而移动,您可以使用计时器来更新它。

var timer = NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: "update", userInfo: nil, repeats: true)

func update() {
    if player.pan == -1.0 {
        timer.invalidate()
        return
    }

    player.pan -= 0.1
}