Search code examples
swiftuislider

How do I change the pitch of a song thats playing using AVPlayer?


Im using avplayer to play my music from the music library and I would like to change the pitch of the music using a UISlider. Is there a pitch property that I can change every-time I move my slider? I tried using audioTimePitchAlgorithm but that didnt work for me. Thanks!

pitchSlider = UISlider(frame:CGRectMake(175 * scaleFactor, 310 * scaleFactor2, 75, 20))
pitchSlider.tintColor = UIColor.redColor()
pitchSlider.maximumTrackTintColor = UIColor.whiteColor()
pitchSlider.transform = CGAffineTransformRotate(pitchSlider.transform, CGFloat(180/360*M_PI))
pitchSlider.value = 1.0
self.view!.addSubview(pitchSlider)

Solution

  • you have to use an AVAudioEngine