Fading audio with AVPlayer
AVPlayer doesn’t provide a built-in way to fade in or out. I previously described how you achieve a video fade-in (or out) using general CoreAnimation layer animation, as part of making a macOS screen saver. Now let’s tackle the audio.
extension AVPlayer {
func fadeAudio(from startVolume: Float, to endVolume: Float, duration: Double) {
let audioMix = AVMutableAudioMix()
[…]

