Photon voice does not work when the application is first installed
Skinzart
✭
in Photon Voice
hi, why does photon voice not work when the application is first installed?
When it is first installed it will ask for microphone permission from the user, then when the user allows it still doesn't work, until the application exits and reopens the application everything goes normally ... thanks in advance
When it is first installed it will ask for microphone permission from the user, then when the user allows it still doesn't work, until the application exits and reopens the application everything goes normally ... thanks in advance
1
Comments
-
public Recorder recorder; void Start() { if (Application.HasUserAuthorization(UserAuthorization.Microphone)) { recorder.IsRecording = true; recorder.TransmitEnabled = true; } else { StartCoroutine(RequestMicPermission()); } } IEnumerator RequestMicPermission() { yield return Application.RequestUserAuthorization(UserAuthorization.Microphone); if (Application.HasUserAuthorization(UserAuthorization.Microphone)) { //permission granted recorder.IsRecording = true; recorder.TransmitEnabled = true; } else { //permission denied, just ignore turning it on. } }
by the way this is the code i use to request permissions, is there something wrong?1 -
Exactly the same problem occurs to me in Android applications, let's wait for a prompt response from the photon team.1
-
Hi @Skinzart, @rrodriguez2020,
Thank you for choosing Photon!
Are you both referring to Android builds right?
On Android use UnityEngine.Android.Permission.HasUserAuthorizedPermission(Permission.Microphone) and UnityEngine.Android.Permission.RequestUserPermission(Permission.Microphone) as shown here. Here is the Unity manual page for the recommendations about how to ask for permissions on Android. You could also directly list the permission in the manifest and ask the user when the app launches and before the microphone is being used by the Recorder.then when the user allows it still doesn't work, until the application exits and reopens the application
If the issue persists:
What Unity version do you use?
What Photon Voice version do you use?
What min/target Android API level do you set?
What Android device model/OS did you test this on?
0 -
So this is my final code
using Photon.Voice.Unity; using UnityEngine; #if PLATFORM_ANDROID using UnityEngine.Android; #endif public class VoiceManager : MonoBehaviour { public static VoiceManager Instance { get; private set; } public Recorder recorder; bool isRequesting; public bool HasPermission { get; private set; } private void Awake() { Instance = this; } public void InitVoice() { #if PLATFORM_ANDROID if (Permission.HasUserAuthorizedPermission(Permission.Microphone)) { HasPermission = true; } else { Permission.RequestUserPermission(Permission.Microphone); isRequesting = true; } #else HasPermission = true; #endif } private void OnApplicationFocus(bool focus) { if (focus && isRequesting) { if (Permission.HasUserAuthorizedPermission(Permission.Microphone)) { HasPermission = true; } else { HasPermission = false; } isRequesting = false; } } public void StartRecording() { if (HasPermission) { recorder.TransmitEnabled = true; recorder.StartRecording(); } } public void StopRecording() { if (HasPermission) { recorder.StopRecording(); recorder.TransmitEnabled = false; } } }
0