问题
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