iPhone 上使用 UIslider 控制音量?

发布于 2024-09-08 11:50:55 字数 666 浏览 7 评论 0 原文

我正在创建一个应用程序,按下按钮时会播放声音,并使用可调节音量的 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; }

}

i am creating a application in which sound is played when a button is pressed and using a UISlider with which volume can be adjusted.Sometimes the volume of sound is too high and sometimes its too low even after increasing the volume of iphone to the full.How can i keep the volume to always high?? any possible way to integrate system volume with slider volume?? Using MPVolumview will get my app rejected i guess..
the code i am using on button touch is this

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅紫色的梦幻 2024-09-15 11:50:55

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 to 1.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 set player.volume always equal to 1.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文