Created
October 6, 2018 11:38
-
-
Save paulhayes/7716ef93e78d7dc8a662f5388db44834 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AndroidAudio | |
{ | |
privateprivate static int GetDeviceMaxVolume() { | |
int streammusic = 3; | |
return deviceAudio.Call<int>("getStreamMaxVolume", streammusic); | |
} | |
private static void SetDeviceVolume(int value) { | |
int streammusic = 3; | |
int flagshowui = 0; | |
deviceAudio.Call("setStreamVolume", streammusic, value, flagshowui); | |
} | |
private static AndroidJavaObject audioManager; | |
private static AndroidJavaObject deviceAudio { get { | |
if(audioManager == null) { | |
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | |
AndroidJavaObject context = up.GetStatic<AndroidJavaObject>("currentActivity"); | |
string audioName = context.GetStatic<string>("AUDIO_SERVICE"); | |
audioManager = context.Call<AndroidJavaObject>("getSystemService", audioName); | |
} | |
return audioManager; | |
} } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment