の値を設定すると、私はAVAudioPlayer
を早送りしています。しかし、私は巻き戻す方法を理解できません。Swiftのレートプロパティを使用して音楽を巻き戻す方法はありますか?
私は、音楽の再生rate
がターンテーブルの回転時に変化し、音楽を早送りして巻き戻す(音を聞こえながら)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
}
削除の代わりに2.0をmusicPlayer.currentTimeに追加しようとしましたか?たぶんそれは残り時間からカウントダウンを開始するかもしれない。 –
はい私は追加しようとし、それでもまだ早送りします。 – coding22