Skip to content

Commit 421648d

Browse files
committed
v8.2update
1 parent 47d1124 commit 421648d

7 files changed

Lines changed: 89 additions & 37 deletions

File tree

Assets/UnityChatSDK/Plugins/Device.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Runtime.InteropServices;
5+
using UnityEngine;
6+
7+
public class ChatSDKDevice : MonoBehaviour
8+
{
9+
10+
#if UNITY_IPHONE
11+
[DllImport("__Internal")]
12+
private static extern void _forceToSpeaker();
13+
[DllImport("__Internal")]
14+
private static extern void _forceToHeadset();
15+
#endif
16+
17+
public static void ToggleSpeaker(bool isOn)
18+
{
19+
#if UNITY_ANDROID
20+
try
21+
{
22+
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
23+
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
24+
AndroidJavaObject audioManager = activity.Call<AndroidJavaObject>("getSystemService", "audio");
25+
26+
if (isOn)
27+
{
28+
audioManager.Call("setMode", 0);
29+
audioManager.Call("setSpeakerphoneOn", true);
30+
}
31+
else
32+
{
33+
audioManager.Call("setMode", 3);
34+
audioManager.Call("setSpeakerphoneOn", false);
35+
}
36+
37+
int mode = audioManager.Call<Int32>("getMode");
38+
bool isSpeakers = audioManager.Call<Boolean>("isSpeakerphoneOn");
39+
40+
Debug.Log("Speakers set to: " + isSpeakers + ",mode is " + mode);
41+
}
42+
catch (Exception e)
43+
{
44+
Debug.Log("ToggleSpeaker Error:" + e.Message);
45+
}
46+
#endif
47+
48+
#if UNITY_IPHONE
49+
try
50+
{
51+
if (isOn)
52+
{
53+
_forceToSpeaker();
54+
}
55+
else
56+
{
57+
_forceToHeadset();
58+
}
59+
}
60+
catch (Exception e)
61+
{
62+
Debug.Log("ToggleSpeaker Error:" + e.Message);
63+
}
64+
#endif
65+
66+
}
67+
}

Assets/UnityChatSDK/Plugins/Device/ChatSDKDevice.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
512 Bytes
Binary file not shown.

Assets/UnityChatSDK/Scripts/UnityChatSet.cs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void InitVideo()
8989
UnityChatSDK.Instance.InitVideo(0);
9090
UnityChatSDK.Instance.SetVideoQuality(VideoQuality);
9191
UnityChatSDK.Instance.SetResolution(VideoResolution);
92-
UnityChatSDK.Instance.ToggleSpeakerAction += ToggleSpeaker;
92+
UnityChatSDK.Instance.ToggleSpeakerAction += ChatSDKDevice.ToggleSpeaker;
9393
switch (VideoType)
9494
{
9595
case VideoType.DeviceCamera:
@@ -186,36 +186,4 @@ public void SetCustomTexture()
186186
{
187187
SetVideoCaptureType(VideoType.CustomTexture, CaptureCamera);
188188
}
189-
190-
public void ToggleSpeaker(bool isOn)
191-
{
192-
#if UNITY_ANDROID
193-
try
194-
{
195-
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
196-
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
197-
AndroidJavaObject audioManager = activity.Call<AndroidJavaObject>("getSystemService", "audio");
198-
199-
if (isOn)
200-
{
201-
audioManager.Call("setMode", 0);
202-
audioManager.Call("setSpeakerphoneOn", true);
203-
}
204-
else
205-
{
206-
audioManager.Call("setMode", 3);
207-
audioManager.Call("setSpeakerphoneOn", false);
208-
}
209-
210-
int mode = audioManager.Call<Int32>("getMode");
211-
bool isSpeakers = audioManager.Call<Boolean>("isSpeakerphoneOn");
212-
213-
Debug.Log("Speakers set to: " + isSpeakers + ",mode is " + mode);
214-
}
215-
catch (Exception e)
216-
{
217-
Debug.Log("ToggleSpeaker Error:" + e.Message);
218-
}
219-
#endif
220-
}
221189
}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
| Tutorials | Location |
3535
| ----------------------------------------------------- | ---------------------------------------------------- |
36-
| UnityChatSDK v8.2 | [View]() |
37-
| | [View]() |
36+
| UnityChatSDK v8.2 | [View](https://www.bilibili.com/video/BV1DY411j7UG/) |
3837
| UnityChatSDK v7.1 | [View](https://www.bilibili.com/video/BV1ZK4y1H7dM/) |
3938
| | [View](https://www.bilibili.com/video/BV1yz4y1m71J/) |
4039
| UnityChatSDK WeChat | [View](https://www.bilibili.com/video/BV1TJ411X79T) |

README.zh.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232

3333
| 视频教程 | 地址 |
3434
| ----------------------------------------------------- | ---------------------------------------------------- |
35-
| UnityChatSDK v8.2 | [观看]() |
36-
| | [观看]() |
35+
| UnityChatSDK v8.2 | [观看](https://www.bilibili.com/video/BV1DY411j7UG/) |
3736
| UnityChatSDK v7.1 | [观看](https://www.bilibili.com/video/BV1ZK4y1H7dM/) |
3837
| | [观看](https://www.bilibili.com/video/BV1yz4y1m71J/) |
3938
| UnityChatSDK WeChat | [观看](https://www.bilibili.com/video/BV1TJ411X79T) |

0 commit comments

Comments
 (0)