AudioPluginAndroid.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using UnityEngine;
  2. namespace SC.XR.Unity.Module_DetectorSystem
  3. {
  4. public class AudioPluginAndroid : AudioPlugin
  5. {
  6. public static AudioPluginAndroid Create()
  7. {
  8. return new AudioPluginAndroid();
  9. }
  10. private AndroidJavaObject AudioPluginAndroidObject;
  11. private AudioUnityListener AudioUnityListener;
  12. AudioPluginAndroid()
  13. {
  14. if (Application.platform == RuntimePlatform.Android)
  15. {
  16. AudioPluginAndroidObject = new AndroidJavaObject("com.xr.audio.AudioActivity", AndroidPluginBase.CurrentActivity, 3, false);
  17. AudioUnityListener = new AudioUnityListener();
  18. AudioPluginAndroidObject.Call("setSoundLister", AudioUnityListener);
  19. }
  20. }
  21. public override void SetType(StreamType type)
  22. {
  23. AudioPluginAndroidObject.Call("setType", (int)type);
  24. }
  25. public override int GetVolume()
  26. {
  27. return AudioPluginAndroidObject.Call<int>("getVolume");
  28. }
  29. public override int GetVolume(int type)
  30. {
  31. return AudioPluginAndroidObject.Call<int>("getVolume", type);
  32. }
  33. public override int GetMaxVolume()
  34. {
  35. return AudioPluginAndroidObject.Call<int>("getMaxVolume");
  36. }
  37. public override void SetVolume(int value)
  38. {
  39. AudioPluginAndroidObject.Call("setVolume", value);
  40. }
  41. public override void SetVolume(int type, int value)
  42. {
  43. AudioPluginAndroidObject.Call("setVolume", type, value);
  44. }
  45. /// <summary>
  46. /// 自动去算 或者自己去算
  47. /// </summary>
  48. /// <param name="calu"></param>
  49. public override void SetAutoCalu(bool calu)
  50. {
  51. AudioPluginAndroidObject.Call("autoCalu", calu);
  52. }
  53. /// <summary>
  54. /// 在脚本失活 注销时调用
  55. /// </summary>
  56. public void UnRegiestAduio()
  57. {
  58. AudioPluginAndroidObject.Call("unRegistVolue");
  59. }
  60. }
  61. }