GregM
GregM

Reputation: 3734

Agora using wrong speaker on iOS device (Unity)

Upon Initializing

   // init engine
    mRtcEngine = IRtcEngine.GetEngine(appId);
    if (mRtcEngine == null)
        return;
    
    mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.CHANNEL_PROFILE_GAME);
    mRtcEngine.SetClientRole(CLIENT_ROLE.BROADCASTER);


    // set callbacks (optional)
    mRtcEngine.OnJoinChannelSuccess = onJoinChannelSuccess;
    mRtcEngine.OnUserJoined = onUserJoined;
    mRtcEngine.OnUserOffline = onUserOffline;
    mRtcEngine.EnableWebSdkInteroperability(true);
    mRtcEngine.OnRemoteVideoStateChanged = OnRemoteVideoStateChangedHandler;
    mRtcEngine.DisableAudio();
    mRtcEngine.EnableAudioVolumeIndication(500, 3, true);
    mRtcEngine.EnableVideo();
    mRtcEngine.EnableVideoObserver();
    mRtcEngine.EnableLocalVideo(false);
    mRtcEngine.SetDefaultAudioRouteToSpeakerphone(true);
    mRtcEngine.AdjustRecordingSignalVolume(0);]
    mRtcEngine.SetLogFilter(LOG_FILTER.DEBUG | LOG_FILTER.INFO | LOG_FILTER.WARNING | LOG_FILTER.ERROR |
                            LOG_FILTER.CRITICAL);

I call mRtcEngine.SetDefaultAudioRouteToSpeakerphone(true);

After I call JoinChannel()

mRtcEngine.JoinChannel(channel, null, 0);
if (mRtcEngine.EnableVideoObserver() == Decimal.Zero)
{
   mRtcEngine.EnableVideoObserver();
}
mRtcEngine.EnableAudio();
mRtcEngine.SetEnableSpeakerphone(true);
    

I call setEnableSpeakerphone(true)

but it still comes out of the ear speaker (as if its a phone call), am I missing a step?

Upvotes: 0

Views: 529

Answers (2)

GregM
GregM

Reputation: 3734

switching from

 mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.CHANNEL_PROFILE_GAME);

to

mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.CHANNEL_PROFILE_COMMUNICATION);

made it work. There is a note in the documentation that the gaming profile doesn't allow changes to the speaker.

Upvotes: 0

Rick Cheng
Rick Cheng

Reputation: 654

The first set of code seems ok to me. But I think you should put the second set of code into the callback handler

// implement engine callbacks
private void onJoinChannelSuccess(string channelName, uint uid, int elapsed)
{
    //    mRtcEngine.EnableVideoObserver(); // you've called this!
    mRtcEngine.EnableAudio();
    mRtcEngine.SetEnableSpeakerphone(true);
}

I tried the code on iPhone and it came out from speaker. Note that you may want to use the demo app as the sender app to test this instead of this rewritten code.

Upvotes: 1

Related Questions