Created
February 1, 2016 10:27
-
-
Save vjyanand/38b7286dfdc0d0670285 to your computer and use it in GitHub Desktop.
fade in fade out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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