我正在创建一个应用程序,当按下按钮时会播放声音并使用可以调节音量的UISlider。有时音量太高,有时甚至在将iphone的音量增加到太低之后我怎么能保持音量始终高?任何可能的方法来集成系统音量和滑块音量?使用MPVolumview会让我的应用程序被拒绝我猜... 我在按钮触摸上使用的代码就是这个
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/sound.mp3"];
NSLog(@"Path to play: %@", resourcePath);
player = [[AVAudioPlayer alloc] initWithContentsOfURL:
[NSURL fileURLWithPath:resourcePath] error:&err];
player.delegate = self;
[player play];
player.volume=.50;
player.numberOfLoops=-10;
-(IBAction)slidervaluechanged
{ player.volume=slider.value; }
}
答案 0 :(得分:3)
与Hemant,
当player.volume
等于1.0
时,您可以拥有的最大音量(只要振铃音量也是最大值)。
如果铃声音量不是最大值,则只能使用1.0
但是,您可以实现MPVolumeView
(我几乎是正面的,因为Pandora会这样做),然后您在应用中使用该滑块。然后,您可以将player.volume
设置为始终等于1.0
,然后让滑块更改铃声音量。
有关您是否要使用MPVolumeView
的更多信息:http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPVolumeView_Class/Reference/Reference.html和How do you implement an MPVolumeView?
我可能错了,但我认为Apple允许MPVolumeView
如果您按原样使用它。他们在课堂参考中说,当你移动滑块时它会改变设备铃声音量(它不常用,这也是人们不得不访问私有API的原因)。我将在一周内尝试在我的下一次更新中实施它,所以如果我被拒绝,我会回到这里并更新这篇帖子,让每个人都知道。