Hello, First of all, I understand that GKVoiceChat has been deprecated and replaced by shareplay but for my situation, it does not seem useful as I will be matching with the random players hence I can not utilise the Facetime(Shareplay) capability.
I have set up a voice chat function using the GKVoiceChat object, my game connects with another player successfully but the voice chat does not work for some reason. The code snippet below is how I implemented it with the help of the tutorial from : apple (Start Voice chat between players)
class OnlineGame {
var voiceChat: GKVoiceChat? = nil
...
// When online game succesfully connected and game view loaded
self.startVoiceChat()
func startVoiceChat() {
// Handle an unknown, connected, or disconnected player state.
/// - Tag:voiceChatChangeHandler
///
if voiceChat == nil {
// Create the voice chat object.
voiceChat = myMatch?.voiceChat(withName: "Gamesession")
}
let voiceChatChangeHandler = { (player: GKPlayer, state: GKVoiceChat.PlayerState) -> Void in
switch state {
case GKVoiceChat.PlayerState.connected:
self.voicechatstate = 1
case GKVoiceChat.PlayerState.disconnected:
self.voicechatstate = 2
case GKVoiceChat.PlayerState.speaking:
self.voicechatstate = 3
case GKVoiceChat.PlayerState.silent:
self.voicechatstate = 4
case GKVoiceChat.PlayerState.connecting:
self.voicechatstate = 5
@unknown default:
print("Player unknown state.")
}
}
// Exit early if the app can't start a voice chat session.
guard let voiceChat = voiceChat else { return }
// Handle an unknown, connected, or disconnected player state.
voiceChat.playerVoiceChatStateDidChangeHandler = voiceChatChangeHandler
// Set the audio volume.
// Activate the shared audio session.
do {
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.gameChat, options: AVAudioSession.CategoryOptions.allowBluetooth)
try audioSession.setActive(true, options: [])
}
catch {
print("ERROR: \(error.localizedDescription).")
}
voiceChat.volume = 0.8
voiceChat.start()
voiceChat.isActive = true
}
}
Thats my implementation of it and hope it explains my issue. Thanks for your assistance in advance!.