Photon voice does not work when the application is first installed

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

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?
  • edited September 4
    Exactly the same problem occurs to me in Android applications, let's wait for a prompt response from the photon team.
  • Maybe @JohnTube any advise?
  • 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
    Maybe you need to restart recording (Recorder.RestartRecording(true)) or disable Recorder.AutoStart and manually/explicitly call Recorder.StartRecording when the permission is granted.

    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?
  • OMG this is my mistake, I didn't check if Application.RequestUserAuthorization only works on IOS, I created a project to target Oculus Quest, so UnityEngine.Android.Permission is used, that's the problem.

    now everything is working fine.

    thank you very much @JohnTube for your support
  • 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;
            }
        }
    }
    

Sign In or Register to comment.