ant-media / Ant-Media-Server

Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
https://antmedia.io
Other
4.23k stars 618 forks source link

[IOS SDK] Playing sound file cause the stream sound disappears #4144

Open denmorgenshtern opened 2 years ago

denmorgenshtern commented 2 years ago

Playing sound while Ant Media Client Mode.publish - the stream sound disappears.

I guess, problem in correct AVAudioSession category/mode? But i've tried different with no success.

My example:

try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
try AVAudioSession.sharedInstance().setActive(true)
player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AV FileType.mp3.rawValue)
player.play()

UPD: Setting

try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .voiceChat)

after audioPlayerDidFinishPlaying partially solves the problem

mekya commented 2 years ago

Hi @denmorgenshtern ,

Sorry for the late response. You're right.

It's likely that when you play a sound, you set the category to the play mode and it just removes microphone record ability.

By default, AVAudioSession is configured by webrtc with .playAndRecord mode. You can get the default configuration with this method

  let webRTCConfiguration = RTCAudioSessionConfiguration.init()

I mean, you can reset the AVAudioSession to the values in webRTCConfiguration after your delegate method is called audioPlayerDidFinishPlaying

I hope it helps, please let me know if we can help further.