简体   繁体   中英

using slider change the volume in AVAudioPlayer in iphone sdk

I am using this code

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]];

NSError *error;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
player.numberOfLoops = -1;

if (player == nil)
    NSLog(@"%@",[error description]);             
else 
    [player play];  

but i want to change the volume so how can i get the volume detail?

Set up your UISlider. Register it to receive the ValueChanged events in IB or programmatically. Set its min value to 0 and max to 100. And that should be it.

- (void)sliderValueChanged:(UISlider *)slider {
  myPlayer.volume = slider.value / 100.0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM