twilio / video-quickstart-ios

Twilio Video Quickstart for iOS
https://www.twilio.com/docs/api/video
MIT License
460 stars 178 forks source link

AVAudioEngine does not play sound locally in a peer-to-peer room #493

Closed luoser closed 4 years ago

luoser commented 4 years ago

Description

AVAudioEngine fails to play music in a Peer to Peer room while waiting for a participant to join.

I understand that in a P2P connection devices wait for another participant in order to publish audio to one another, but playing audio locally should still work with the AVAudioEngine. It is a common use case to play waiting music while waiting for a participant to join a call.

Steps to Reproduce

  1. Implement AVAudioEngineDevice from example repo https://github.com/twilio/video-quickstart-ios/tree/master/AudioDeviceExample
  2. Switch your room from Group to Peer to Peer
  3. Sound effects do not play unless there are > 1 participants in the room

Expected Behavior

Sounds can play locally via the AVAudioEngine even if there is only one participant in the room.

Actual Behavior

Sounds do not play via the AVAudioEngine if there is only one participant in the room.

Reproduces How Often

100%

Versions

3x

Video iOS SDK

3.2.5 via CocoaPods

Xcode

11.4.1

iOS Version

12 and 13+

iOS Device

iPhone 6, iPhone X

piyushtank commented 4 years ago

@luoser Thats correct - what you are observing is an expected behavior. For peer to peer Rooms, the video sdk's media engine doesn't start until the first participant joins. You will have to implement the logic in your app if you like to play an audio file before a remote participant joins.

luoser commented 4 years ago

@piyushtank thank you for the quick reply. The issue is, I need to connect to the room (set the local audio track) in order to join the room and observe the participantDidConnect or roomDidConnect callbacks. If I play a sound URL using AVAudioPlayer, in my experience with TwilioVideo it has caused issues with the call audio being muted when the participant does connect (https://github.com/twilio/video-quickstart-ios/issues/402).

Is there a particular way to handle playing the sound effect with AVAudioPlayer then restoring the playout and record engine of the audio device set for the call?

piyushtank commented 4 years ago

@luoser Yes thats because the real time audio configuration takes over the audio once another participant joins the Call in peer to peer Room. I don't see a better way of achieving an uninterrupted audio from AVPlayer other than -

  1. If there is no participant in the Room, and you want to play a file after connected, then start your AVAudioEngineAudioDevice in your app - you app code should explicitly call init and start on rendering side. Please note that Video SDK will invoke init/start callbacks when remote participant joins the Room - your custom audio device should handle this case.

  2. Another alternative is, built up your server to create a Room and have one participant in a Room to support this used case. You app needs to ignore that participant.

Let me know if you have any questions.

VishalSharma91 commented 3 years ago

@piyushtank I have tried the above solution using AVAudioEngineAudioDevice just when my call screen shows up. But it didn't work. Nothing plays. The play works fine on any other screen of the app that means the function is correct.

At this point no participant has joined only I am alone in the room. I would like to play ringtone like whtsapp or other apps does till the receiver picks up.

I am using exactly same twilioVideo starter example.

piyushtank commented 3 years ago

@VishalSharma91 Can you make sure that your app invokes the suggested callbacks in the post above?