Question

I have an issue with GKVoiceChat on iphone. When i test the voice chat with an iphone and an ipad, the output sound from the ipad is loud and clear through the speakers but when it comes to the iphone to output the voice i have to put it to my ear to hear the voice.

Can i select the audio output so i can hear thge chat from the loud speakers ?

- (void) establishChat
{
    audioChat = YES;
    chat = [activeMatch voiceChatWithName:@"com.fazan.chat"];
    if (!chat)
    {
        NSLog(@"Error establishing chat!");
        return;
    }

    chat.playerStateUpdateHandler = ^(NSString *playerID, GKVoiceChatPlayerState state) {
        switch (state)
        {
            case GKVoiceChatPlayerSpeaking:
                NSLog(@"***Speaking: %@", playerID);
                // Highlight player's picture
                break;
            case GKVoiceChatPlayerSilent:
                NSLog(@"***Silent: %@", playerID);
                // Dim player's picture
                break;
            case GKVoiceChatPlayerConnected:
                NSLog(@"***Connected: %@", playerID);
                // Show player name/picture
                break;
            case GKVoiceChatPlayerDisconnected:
                NSLog(@"***Disconnected: %@", playerID);
                // Hide player name/picture
                break;
        } };


    chat.active = NO; // disable mic by setting to NO
    chat.volume = 1.0f; // adjust as needed.

    NSLog(@"Connecting to channel");
    [chat start]; // stop with [chat end];

    NSLog(@"Chat: %@", chat.description);
    NSLog(@"Participants: %@", chat.playerIDs);

    // Establishing team chats and direct chat
    /*
     e.g. directChat = [match voiceChatWithName:@"Private Channel 1"];
     Each unique name specifies the chat
     */

    // muting: [chat setMute:YES/NO forPlayer: playerID];
}
Was it helpful?

Solution

The reason for this is that the iPhone defaults to route audio to the "receiver" speaker (the one by your ear) rather than the built-in speaker at the bottom when you also have input enabled (as with two way chat in games). iPad doesn't have a "receiver" speaker, so it just goes to the built in speaker.

You can override this default using the AudioSession API. Do this right after you set the session category to PlayAndRecord:

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);

A word of warning though – playing the chat out the speaker will lead to some feedback since the audio coming out the speaker will be picked up by the microphone. Best to use headphones with built in mic for this kind of thing...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top