iPhone 上使用 UIslider 控制音量?
我正在创建一个应用程序,按下按钮时会播放声音,并使用可调节音量的 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; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hemant,
您可以拥有的最大音量是当
player.volume
等于1.0
时(只要铃声音量也一直是最大)。如果铃声音量不是最大,您只能再次使用
1.0
的值来调高音量。但是,您可以实现
MPVolumeView
(我几乎是肯定的,就像潘多拉那样),然后您在应用程序中使用该滑块。然后,您只需将player.volume
设置为始终等于1.0
并让滑块更改铃声音量即可。有关是否要使用
MPVolumeView
的更多信息:http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPVolumeView_Class/Reference/Reference.html 和 如何实现 MPVolumeView?我可能是错的,但我认为 Apple 允许
MPVolumeView
如果您按原样使用它。他们在类参考中说,现在当您移动滑块时,它会更改设备铃声音量(它不习惯,这就是为什么人们必须访问私有 API 才能做到这一点)。我将尝试在一周后的下一次更新中实现它,所以如果我被拒绝,我会回到这里并更新这篇文章以让每个人都知道。Hemant,
The maximum volume you can have is when
player.volume
is equal to1.0
(so long as the ringer volume is all the way maximum as well).If the ringer volume is not at maximum, you can only go as high as whatever it is at by again using the value of
1.0
However, you could implement the
MPVolumeView
(I'm almost positive, as Pandora does it) and then you use that slider in your app instead. Then you can just setplayer.volume
always equal to1.0
and let the slider change the ringer volume.More information on if you want to use
MPVolumeView
: http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPVolumeView_Class/Reference/Reference.html and How do you implement an MPVolumeView?I may be wrong, but I think Apple allows
MPVolumeView
if you use it as-is. They say in the class reference that it now changes the device ringer volume when you move the slider (which it didn't used to and that's why people were having to access private API to do). I'm going to try and implement it on my next update here in a week, so if I get rejected, I'll come back here and update this post to let everyone know.