Skip to content

Instantly share code, notes, and snippets.

@vjyanand
Created February 1, 2016 10:27
Show Gist options
  • Save vjyanand/38b7286dfdc0d0670285 to your computer and use it in GitHub Desktop.
Save vjyanand/38b7286dfdc0d0670285 to your computer and use it in GitHub Desktop.
fade in fade out
let avUrlAsset = AVAsset(URL: _url)
let duration = avUrlAsset.duration
let durationInSeconds = CMTimeGetSeconds(duration)
let item = AVPlayerItem(asset: avUrlAsset, automaticallyLoadedAssetKeys:["duration"])
let params = AVMutableAudioMixInputParameters(track: avUrlAsset.tracks.first! as AVAssetTrack)
let firstSecond = CMTimeRangeMake(CMTimeMakeWithSeconds(0, 1), CMTimeMakeWithSeconds(15, 1))
let lastSecond = CMTimeRangeMake(CMTimeMakeWithSeconds(durationInSeconds - 1, 1), CMTimeMakeWithSeconds(1, 1))
params.setVolumeRampFromStartVolume(0, toEndVolume: 1, timeRange: firstSecond)
params.setVolumeRampFromStartVolume(1, toEndVolume: 0, timeRange: lastSecond)
let mix = AVMutableAudioMix()
mix.inputParameters = [params]
item.audioMix = mix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment