Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Swift中是否有使用rate属性回放音乐的方法?_Ios_Xcode_Swift_Swift2_Avaudioplayer - Fatal编程技术网

Ios 在Swift中是否有使用rate属性回放音乐的方法?

Ios 在Swift中是否有使用rate属性回放音乐的方法?,ios,xcode,swift,swift2,avaudioplayer,Ios,Xcode,Swift,Swift2,Avaudioplayer,我正在通过设置速率值快速转发我的AVAudioPlayer。但是我不知道如何倒带 我正在制作一个DJ应用程序,在旋转转盘时,音乐的播放速率发生变化,导致音乐快进和快退(同时仍能听到声音) 这是我目前转盘旋转的方法。如何倒带AVAudioPlayer override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch in touches { let locatio

我正在通过设置
速率
值快速转发我的
AVAudioPlayer
。但是我不知道如何倒带

我正在制作一个DJ应用程序,在旋转转盘时,音乐的播放<代码>速率发生变化,导致音乐快进和快退(同时仍能听到声音)

这是我目前转盘旋转的方法。如何倒带
AVAudioPlayer

 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 {

            // Code to rewind music goes here....
            print("rotateleft")


        } else {
            //This code works perfectly and fast forwards the music when spinning turntable to right
            print("rotateright")
            musicPlayer.rate = 2.0
            musicPlayer.play()
        }

        previousAngle = angle2
 }
覆盖功能触摸移动(触摸:设置,带事件:UIEvent?){
接触{
let location=touch.locationInNode(自)
设node=self.nodeAtPoint(位置)
//这是左转盘的
如果node.name==“lefttt”{
//当转盘上有一个手指时,允许用户旋转左转盘。
设dy=左转盘.position.y-位置.y
设dx=左转盘.position.x-location.x
设角度2=atan2(dy,dx)
leftTurntable.z旋转=角度2
设δ=(角度2-上一个角度)
如果增量>0{
//这里有回放音乐的代码。。。。
打印(“rotateleft”)
}否则{
//当转盘向右旋转时,此代码可以完美地快速播放音乐
打印(“旋转右”)
MusicLayer.rate=2.0
musicPlayer.play()
}
上一个角度=角度2
}

您可以通过将
currentTime
设置为小于其当前值的值来倒带

我不认为这会以某种可听见的方式倒转。你不会神奇地听到音乐倒转或诸如此类的声音。AVAudioPlayer不会这样做。但是,它会改变播放位置,这样当你再次开始播放(向前)时,你会比原来的位置更早开始播放


AVPlayer(与AVAudioPlayer相反)可以反向播放,但前提是特定的AVPlayerItem允许。

您是否尝试过将2.0添加到MusicLayer.currentTime而不是减法?可能它开始从剩余时间开始倒数。是的,我尝试过添加,但它仍然快速向前。我告诉您的信息与您在que上获得的信息基本相同这里的问题:不要多次问同一个问题,试着听你给出的答案。这个问题是关于倒带,而不是快进。这个问题不是重复的。OP显然知道如何快进(根据附带的
触摸移动
方法)@AleksanderAzizi这是一个重复的问题,因为他已经被告知他不能在AVAudioPlayer上向后玩。他一直问同样的问题,因为他不接受这个事实。我现在看到OP已经多次发布这个问题。但是,这个问题仍然不是重复的,应该标记为关闭,而不是重复。