Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding nearest zero-crossing in an AVURLAsset
    primarykey
    data
    text
    <p>I'm trying to find a way to fade in an audio track held locally without an audio glitch. I'm using AVPlayer and referencing mp3s from the iPodLibrary using AVURLAsset. The following method works most of the time but not all the time so I'm thinking I need to scan through the audio data looking for the nearest volume zero-crossing and do my fade from there. Any pointers would be much appreciated.</p> <pre><code>float duration = 0.5; AVAsset *asset = [self.av_Player.currentItem asset]; NSArray *keys = [NSArray arrayWithObject:@"tracks"]; [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^(void) { NSError *error = nil; NSTimeInterval now = [self currentPlaybackTime]; CMTime mainFadeIn = CMTimeMakeWithSeconds(now, 6000); CMTime mainFadeDuration = CMTimeMakeWithSeconds(duration, 6000); CMTimeRange timerange = CMTimeRangeMake(mainFadeIn, mainFadeDuration); AVKeyValueStatus trackStatus = [asset statusOfValueForKey:@"tracks" error:&amp;error]; switch (trackStatus) { case AVKeyValueStatusLoaded: if( self.av_Player ) { NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeAudio]; AVMutableAudioMixInputParameters *volumeMixInput = [AVMutableAudioMixInputParameters audioMixInputParameters]; [volumeMixInput setVolumeRampFromStartVolume:0.0 toEndVolume:tovolume timeRange:timerange]; [volumeMixInput setTrackID:[[tracks objectAtIndex:0] trackID]]; AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; [audioMix setInputParameters:[NSArray arrayWithObject:volumeMixInput]]; [self.av_Player.currentItem setAudioMix:audioMix]; } break; default: break; } }]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload