AVPlayeruses the system volume, so if you need to provide controls for this, you can use MPVolumeViewthat gives you a slider for adjusting the volume.
You can use to fade out the sound AVAudioMix. Here is the code:
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
id audioMix = [[AVAudioMix alloc] init];
id volumeMixInput = [[AVMutableAudioMixInputParameters alloc] init];
[volumeMixInput setVolumeRampFromStartVolume:0 toEndVolume:1 timeRange:
CMTimeRangeMake(CMTimeMakeWithSeconds(0, 1), CMTimeMakeWithSeconds(3, 1))];
[volumeMixnput setTrackID:[[asset tracks:objectAtIndex:0] trackID]];
[audioMix setInputParameters:[NSArray arrayWithObject:volumeMixInput]];
[playerItem setAudioMix:audioMix];
You can also sharply set the volume for the mix at a given time with:
[volumeMixInput setVolume:.5 atTime:CMTimeMakeWithSeconds(15, 1)]
, . API . WWDC 10 " AV Foundation". .