有没有办法使用AVAudioPlayer回放音乐?

时间:2016-04-14 03:07:14

标签: ios xcode swift swift2 avaudioplayer

我正在使用AVAudioPlayer播放音乐,需要帮助重绕音乐。我使用rate = 2.0快速前进,但现在我不知道如何使用rate属性或其他东西来回放音乐。有人可以帮我解决这个问题。谢谢!

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {

    for touch in touches {
        let location = touch.locationInNode(self)
        let node = self.nodeAtPoint(location)


        //this is for the left turntable
        if node.name == "lefttt" {

            //lets user rotate left turntable when there is one finger on turntable.
            let dy = leftTurntable.position.y - location.y
            let dx = leftTurntable.position.x - location.x
            let angle2 = atan2(dy, dx)
            leftTurntable.zRotation = angle2


            let delta = (angle2 - previousAngle)
            if delta > 0 {

                //rewind code
                print("rotateleft")
            }
            else {
                print("rotateright")

                musicPlayer.rate = 2
                musicPlayer.play()


            }
            previousAngle = angle2
       }

1 个答案:

答案 0 :(得分:0)

AVAudioplayer不提供任何直接的方法来回放音乐。但您可以通过滑块/按钮或任何其他方式手动设置'currentTime'属性

来自Apple doc: currentTime

  

通过设置此属性,您可以搜索声音中的特定点   提供或实现音频快进和快退功能。


或者,如果您想使用费率属性,可以使用AVPlayer。它还支持以速率倒带: 您可以在此处找到有关AVPlayer倒带的更多信息:https://stackoverflow.com/a/10761446/4557505