0

I have an app in which I stream radios thanks to a URL in a AVPlayer :

NSURL *myURL = [NSURL URLWithString:urlString];

    AVPlayer *player = [[AVPlayer alloc]initWithURL:myURL];
    self.player = player;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playerItemDidReachEnd:)
                                                 name:AVPlayerItemDidPlayToEndTimeNotification
                                               object:[self.player currentItem]];
    [self.player addObserver:self forKeyPath:@"status" options:0 context:nil];
    [self.player play];

What I would like is to have a slider to control the volume. I know that with an AVAudioPlayer it's easy because there's a property, but not with AVPlayer.

How could I do this ? Do I have to use AVAsset as I saw there, and how (as I don't use them at all in my code right now)?

Thanks yall !

Community
  • 1
  • 1
Nicolas Roy
  • 3,773
  • 5
  • 27
  • 42

1 Answers1

0

You will have to create a AVMutableAudioMix with the volume as specified in a UISlider valueChanged: action. Something like this:

- (IBAction) sliderValueChanged:(UISlider *)sender {
    AVMutableAudioMixInputParameters *audioInputParams = 
    [AVMutableAudioMixInputParameters audioMixInputParameters];
    [audioInputParams setVolume:sender.value atTime:kCMTimeZero];
    AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
    [audioMix setInputParameters:@[audioInputParams]];
    [[player currentItem] setAudioMix:audioMix]; (from a UISlider valueChanged action)
}
Chris Truman
  • 913
  • 1
  • 7
  • 25