using slider change the volume in AVAudioPlayer in iphone sdk

十年热恋 提交于 2019-12-08 11:42:20

问题


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?


回答1:


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;
}


来源:https://stackoverflow.com/questions/11795624/using-slider-change-the-volume-in-avaudioplayer-in-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!