Unity3D: is it possible to check the volume of both Android and iPhone devices?

天大地大妈咪最大 提交于 2019-12-22 10:25:59

问题


I have the following code:

void Update(){
    GetComponent<UnityEngine.UI.Text> ().text = AudioListener.volume.ToString();
}

After pushing to my Android device, it always says "1" when I push the physical volume buttons of the Android. So it is not detecting what the volume of the phone actually is. Is it possible to check the current volume of the phone?

I'm working with the Google Cardboard SDK. Maybe that's important as it uses several cameras at the same time. Maybe is it something related with permissions?


回答1:


Just for the record,

It's a great question, can you get the phone volume setting, from Unity?

Firstly: do note that AudioListener.volume is totally unrelated. That is simply the volume as Unity thinks of it for your playing music or sound effects.

Secondly: I'm afraid to say, I'm fairly sure there is no way to get the phone volume setting, from Unity, as of 2016.

If someone knows better - answer!

Nice question.


UPDATE (from comments)

Note. It is possibly possible to control system volume. But OP would have to write native plugins for that.

Consider these QA:

  • For Android: How do you get/set media volume (not ringtone volume) in Android?
  • For iOS: iOS 9: How to change volume programmatically without showing system sound bar popup?

Note however that changing the volume in iOS (nothing to do with Unity) is a tricky issue regarding whether Apple approve it on the app store. Same for Android. These issues are unrelated to Unity and require knowledge about the app store, Samsung hardware, etc, in whatever year you are reading this. AND note that in many QA about "changing volume" on phones, there is again simply confusion about changing the volume of something in an app versus "the actual phone volume control".



来源:https://stackoverflow.com/questions/37057723/unity3d-is-it-possible-to-check-the-volume-of-both-android-and-iphone-devices

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