ios iPhone - 无法使用硬按钮调节音量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7595434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:40:37  来源:igfitidea点击:

iPhone - Can't adjust sound volume with hard buttons

iphoneiosaudiohardwarevolume

提问by Oliver

When my app is launched (no sound emitted, Ambiant category set for AudioSession), using the up and down volume button on the iPhone does not do anything : - on screen, nothing is displayed (I mean, the iOS black and white "slider" overlay does not appear to show me that volume is changing). - in app, after playing with hard buttons, no impact on the sound volume when some sound is played (I use an AVAudioPlayer) - this is the same if I quit the app, adjust the sound volume (onscreen "slider"overlay shows up to show me that the sound level have decreased for example), kill the app and relaunch it : same sound level that before

当我的应用程序启动时(没有发出声音,为 AudioSession 设置了 Ambiant 类别),使用 iPhone 上的上下音量按钮不会做任何事情: - 在屏幕上,没有显示任何内容(我的意思是,iOS 黑白“滑块" 覆盖似乎没有向我显示音量正在变化)。- 在应用程序中,使用硬按钮播放后,播放某些声音时对音量没有影响(我使用 AVAudioPlayer) - 如果我退出应用程序,调整音量(屏幕上显示“滑块”叠加显示)也是如此例如,向我展示声级已降低),杀死应用程序并重新启动它:与之前相同的声级

Using those hard buttons work though on the springboard and into other apps ("slider" overlay is displayed and volume is changing).

使用这些硬按钮可以在跳板上和其他应用程序中使用(显示“滑块”覆盖并且音量正在变化)。

What is the problem with my app ?

我的应用程序有什么问题?

As far as I've seen, many app, and angry birds for an example, make sounds, does not have a hard slider to change it's volume when playing game, and sound can be adjusted just playing with hard buttons.

据我所知,许多应用程序,例如愤怒的小鸟,都会发出声音,在玩游戏时没有硬滑块来改变音量,只需使用硬按钮即可调整声音。

回答by Samuel

I got some users of my app with the same problem, it was not my code but their iPhone settings:

我的应用程序的一些用户遇到了同样的问题,这不是我的代码,而是他们的 iPhone 设置:

Go to Settings->Sound->Change with Buttons and set it to Off

转到设置->声音->使用按钮更改并将其设置为关闭

回答by Max MacLeod

How your app behaves with that stuff depends on how you have set up your audio session. There are as I recall five different categories to choose from. Which category you choose affects how your app behaves with respect to hardware buttons, volume, backgrounding, and so on.

您的应用程序如何处理这些内容取决于您如何设置音频会话。我记得有五个不同的类别可供选择。您选择的类别会影响您的应用程序在硬件按钮、音量、背景等方面的行为方式。

Best bet is to have a look at the Apple docs here:

最好的办法是在这里查看 Apple 文档:

http://developer.apple.com/library/ios/#DOCUMENTATION/Audio/Conceptual/AudioSessionProgrammingGuide/Configuration/Configuration.html#//apple_ref/doc/uid/TP40007875-CH3-SW1

http://developer.apple.com/library/ios/#DOCUMENTATION/Audio/Conceptual/AudioSessionProgrammingGuide/Configuration/Configuration.html#//apple_ref/doc/uid/TP40007875-CH3-SW1

Also, there is a really great tutorial video by Apple that covers this stuff really well. Here's the link:

此外,Apple 提供了一个非常棒的教程视频,它很好地涵盖了这些内容。这是链接:

https://developer.apple.com/videos/iphone/#video-advanced-audiodev

https://developer.apple.com/videos/iphone/#video-advanced-audiodev