2014-02-15 47 views
0

我在iPhone上的GKVoiceChat有問題。當我用iphone和ipad測試語音聊天時,ipad的輸出聲音通過揚聲器響亮而清晰,但當涉及到iphone輸出聲音時,我必須將它放在耳邊才能聽到聲音。IOS GKVoiceChat iphone

我可以選擇音頻輸出,以便我可以聽到來自揚聲器的聊天內容嗎?

- (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]; 
} 

回答

0

這樣做的原因是iPhone的默認路由音頻的「接收器」揚聲器(一個由你的耳朵),而不是內置的底部揚聲器的時候,你還可以輸入使能(如在遊戲中雙向聊天)。 iPad沒有「接收器」揚聲器,所以它只能使用內置揚聲器。

您可以使用AudioSession API覆蓋此默認設置。您設置會話類別PlayAndRecord後做的權利:

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

警告詞雖然 - 玩聊天出來的揚聲器會導致一些反饋問世以來的揚聲器的音頻將被麥克風拾取。最適合使用內置麥克風的耳機來播放這種東西...