aws-samples / amazon-chime-react-native-demo

A React Native demo application for Android and iOS using the Amazon Chime SDK.
MIT No Attribution
100 stars 24 forks source link

Unable to on the speaker when we join the call we have referred this issue as reference https://github.com/aws-samples/amazon-chime-react-native-demo/issues/5 #211

Closed Anirudhastikar closed 4 days ago

Anirudhastikar commented 3 weeks ago

Unable to on the speaker when we are join the call we have referred the issue as reference https://github.com/aws-samples/amazon-chime-react-native-demo/issues/5

this is the bridge code where the audio code is written

private fun startAudioVideo() {
    meetingSession?.let {
        val audioDevices = it.audioVideo.listAudioDevices().filter {
            it.type != MediaDeviceType.OTHER
        }
        val device = audioDevices.find { ad -> ad.type == MediaDeviceType.AUDIO_BUILTIN_SPEAKER}
        it.audioVideo.chooseAudioDevice(device!!)

        it.audioVideo.addRealtimeObserver(meetingObservers)
        it.audioVideo.addVideoTileObserver(meetingObservers)
        it.audioVideo.addAudioVideoObserver(meetingObservers)
        it.audioVideo.addRealtimeDataMessageObserver(TOPIC_CHAT, meetingObservers)
        it.audioVideo.start()
        it.audioVideo.startRemoteVideo()
    }
}

and need help on camera switching front and back

amplify version is 12.0.3

BBopanna commented 3 weeks ago

We have tried with the above code but does not work - audio is coming only in the ear piece - NOT speaker - requirement is to have the audio on speaker. Also we have referred this with no luck - https://github.com/aws-samples/amazon-chime-react-native-demo/issues/5

BBopanna commented 3 weeks ago

Any update ?

Anirudhastikar commented 3 weeks ago

For Kotlin we tried this and it work by adding it in NativeMobileSDKBridge.m

@ReactMethod
        fun setSpeakerOn() {
            logger.info(TAG, "Called setSpeakerOn")
            // Filter out OTHER type which is currently not supported for selection
            val device :  MediaDevice ? = meetingSession?.audioVideo?.listAudioDevices()?.find { ad -> ad.type == MediaDeviceType.AUDIO_BUILTIN_SPEAKER }
            meetingSession?.audioVideo?.chooseAudioDevice(device!!)
        }

and for ios we tried this by adding it in NativeMobileSDKBridge.m

-(void)startAudioClient
{
  if (meetingSession == nil)
  {
    [logger errorWithMsg:@"meetingSession is not initialized"];
    return;
  }
  MeetingObservers* observer = [[MeetingObservers alloc] initWithBridge:self logger:logger];
  [meetingSession.audioVideo addRealtimeObserverWithObserver:observer];
  [meetingSession.audioVideo addVideoTileObserverWithObserver:observer];
  [meetingSession.audioVideo addAudioVideoObserverWithObserver:observer];
  [meetingSession.audioVideo addRealtimeDataMessageObserverWithTopic:@"chat" observer:observer];
// Enable the speaker
  [self startAudioVideo];
    [self enableSpeaker];
}

-(void)enableSpeaker
{
   // List available audio devices
       NSArray<MediaDevice *> *audioDevices = [meetingSession.audioVideo listAudioDevices];
       // Log the audio devices
       NSLog(@"Available audio devices:");
       for (MediaDevice *device in audioDevices) {
           NSLog(@"Device: %@", device);
       }
       // Find and select the speaker device
       MediaDevice *speakerDevice = nil;
       for (MediaDevice *device in audioDevices) {
           if (device.type == MediaDeviceTypeAudioBluetooth) {
               NSLog(@"Device inside: %@", device);
               speakerDevice = device;
               break;
           }
           if (device.type == MediaDeviceTypeAudioWiredHeadset) {
               NSLog(@"Device inside: %@", device);
               speakerDevice = device;
               break;
           }
           if (device.type == MediaDeviceTypeAudioBuiltInSpeaker) {
               NSLog(@"Device inside: %@", device);
               speakerDevice = device;
               break;
           }
       }
       if (speakerDevice) {
           // Set the speaker device as the active audio device
           [meetingSession.audioVideo chooseAudioDeviceWithMediaDevice:speakerDevice];
           [logger infoWithMsg:@"Speaker device selected."];
       } else {
           [logger errorWithMsg:@"No speaker device found."];
       }
}
georgezy-amzn commented 4 days ago

Thanks @Anirudhastikar!