'How to add AVAudioUnitEQ effects on AVPlayer

I am trying achive to add equalizer effects on AVPlayer. Basically need reverb and frequency band change of audio sound on Video Playback.

class ViewController: UIViewController {

let engine = AVAudioEngine()
let reverb = AVAudioUnitReverb()
var sourceFile: AVAudioFile!
var format: AVAudioFormat!

override func viewDidLoad() {
    super.viewDidLoad()
    setupAudioEngine()
}

func setupAudioEngine() {
    do {
        let sourceFileURL = Bundle.main.url(forResource: "videosong", withExtension: "mp4")!
        sourceFile = try AVAudioFile(forReading: sourceFileURL)
        format = sourceFile.processingFormat
    } catch {
        fatalError("could not open source audio file, \(error)")
    }
    let player = AVAudioPlayerNode()
    engine.attach(player)
    engine.attach(reverb)
    // set desired reverb parameters
    reverb.loadFactoryPreset(.mediumHall)
    reverb.wetDryMix = 70
    
    // make connections
    engine.connect(player, to: reverb, format: format)
    engine.connect(reverb, to: engine.mainMixerNode, format: format)
    
    // schedule source file
    player.scheduleFile(sourceFile, at: nil)
    do {
        try engine.start()
        player.play()
    } catch {
        fatalError("could not start engine, \(error)")
    }
  //  SaveFile()
}

}

I am using Video file in mp4 formate. and i need to achieve reverb effect on video playback.
How we can use AVPlayer as input node are any other way ? Please Help me in this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source