Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let type = AVMediaTypeAudio
- let asset1 = AVURLAsset(URL: beatLocationURL, options: nil)
- let arr2 = asset1.tracksWithMediaType(type)
- let track2 = arr2.last as AVAssetTrack
- track2.preferredVolume(beatVolume.value) <--where error occurs
- let duration : CMTime = track2.timeRange.duration
- let comp = AVMutableComposition()
- let comptrack = comp.addMutableTrackWithMediaType(type,
- preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
- comptrack.insertTimeRange(CMTimeRangeMake(CMTimeMakeWithSeconds(0,600), CMTimeMakeWithSeconds(5,600)), ofTrack:track2, atTime:CMTimeMakeWithSeconds(0,600), error:nil)
- comptrack.insertTimeRange(CMTimeRangeMake(CMTimeSubtract(duration, CMTimeMakeWithSeconds(5,600)), CMTimeMakeWithSeconds(5,600)), ofTrack:track2, atTime:CMTimeMakeWithSeconds(5,600), error:nil)
- let type3 = AVMediaTypeAudio
- let asset = AVURLAsset(URL: vocalURL, options:nil)
- let arr3 = asset.tracksWithMediaType(type3)
- let track3 = arr3.last as AVAssetTrack
- let comptrack3 = comp.addMutableTrackWithMediaType(type3, preferredTrackID:Int32(kCMPersistentTrackID_Invalid))
- comptrack3.insertTimeRange(CMTimeRangeMake(CMTimeMakeWithSeconds(0,600), CMTimeMakeWithSeconds(10,600)), ofTrack:track3, atTime:CMTimeMakeWithSeconds(0,600), error:nil)
- let params = AVMutableAudioMixInputParameters(track:comptrack3)
- params.setVolume(1, atTime:CMTimeMakeWithSeconds(0,600))
- params.setVolumeRampFromStartVolume(1, toEndVolume:0, timeRange:CMTimeRangeMake(CMTimeMakeWithSeconds(7,600), CMTimeMakeWithSeconds(3,600)))
- let mix = AVMutableAudioMix()
- mix.inputParameters = [params]
- let item = AVPlayerItem(asset:comp)
- item.audioMix = mix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement