Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you might be visualizing it incorrectly. An AVMutableAudioMix instance is actually a <a href="http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayerItem_Class/Reference/Reference.html#//apple_ref/occ/instp/AVPlayerItem/audioMix" rel="nofollow noreferrer">property</a> on the AVPlayerItem class. First grab the track of the asset using <a href="http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAsset_Class/Reference/Reference.html#//apple_ref/occ/instm/AVAsset/tracksWithMediaType:" rel="nofollow noreferrer">tracksWithMediaType:</a> and create an <a href="http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVMutableAudioMixInputParameters_Class/Reference/Reference.html" rel="nofollow noreferrer">AVMutableAudioMixInputParameters</a> instance using <a href="http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVMutableAudioMixInputParameters_Class/Reference/Reference.html#//apple_ref/occ/clm/AVMutableAudioMixInputParameters/audioMixInputParametersWithTrack:" rel="nofollow noreferrer">audioMixInputParametersWithTrack:</a>. Set any audio properties on that inputparameters instance, (for instance setVolume:atTime).</p> <p>Then you need to add the input parameters onto an AVMutableAudioMix instance. Then you need to add this to an player item. I know this sounds confusing, but this is exactly how AVFoundation works with just about everything. There's terms flying around all over the place, but pretty much everything has a hierarchy. </p> <p>So the general hierarchy is this: player->playerItem->audioMix->inputParameters. The code to ramp down the volume from the 5 to 7 second mark should look something like this:</p> <pre><code>AVAssetTrack *audioTrack = [[self.player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]; AVMutableAudioMixInputParameters *params = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:audioTrack]; [params setVolumeRampFromStartVolume:1.0 toEndVolume:0.5 timeRange:CMTimeRangeMake(CMTimeMake(5,1), CMTimeMake(2,1))]; AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; audioMix.inputParameters = [NSArray arrayWithObject:params]; self.player.currentItem.audioMix = audioMix; </code></pre> <p>As far as doing this dynamically, you can, but only with local files (as opposed to streaming from the internet). I would probably try to keep this audioMix as an ivar and try resetting the params every time you want something to happen. If that doesn't work, you may have to create an instance of AVMutableAudioMix every time, not sure.</p> <p>Also see <a href="https://stackoverflow.com/questions/3268949/adjusting-the-volume-of-a-playing-avplayer">this post</a> and <a href="http://developer.apple.com/library/ios/#qa/qa1716/_index.html" rel="nofollow noreferrer">this</a>. </p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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