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

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

Can't able to switch audio devices, like speaker to earpiece and vice versa #158

Closed ashirkhanpm closed 2 years ago

ashirkhanpm commented 2 years ago

Hi, How can I switch to the specific audio device [bluetooth/earpiece/speaker/headset], when using the demo app , found something similar on #93 , but it's only connecting to a recently connected device

ziyiz-amzn commented 2 years ago

Hi @ashirkhanpm Thank you for report this and your interest in Amazon Chime mobile SDK.

You can use chooseAudioDevice and listAudioDevices to do this (Android iOS). You will also have to update the bridge and observer so that you can call these from React Native (Android iOS). In this demo, we provide some basic examples of bridging, you can bring in more bridge function by referring these examples.

You can use https://github.com/aws-samples/amazon-chime-react-native-demo/pull/93 as a reference as well.

ashirkhanpm commented 2 years ago

Hi, @ziyiz-amzn thanks for your replay, and I already tried with the chooseAudioDevice and listAudioDevices, but IOS app getting crashed when trying

RCT_EXPORT_METHOD(switchToEarPice) { NSArray<MediaDevice *> *AudioDevices=[meetingSession.audioVideo listAudioDevices]; NSString *dictionaryKey = @"type"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K MATCHES %@",dictionaryKey,MediaDeviceTypeAudioHandset]; NSArray *results= [AudioDevices filteredArrayUsingPredicate:predicate]; [meetingSession.audioVideo chooseAudioDeviceWithMediaDevice:results[0]]; NSLog(@"test-Audio-list earpice %@",results ); }

this is my code, is this the right way? or How can I filter one audio device from the available AudioDevices list with type

ziyiz-amzn commented 2 years ago

I think it is the correct approach. You will need to debug the result you get from meetingSession.audioVideo.listAudioDevices() and then see if the filter you implement works. Any error reported before the crash?

ashirkhanpm commented 2 years ago

@ziyiz-amzn thanks for your replay I think the issue in the filtering line NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K MATCHES %@",dictionaryKey,MediaDeviceTypeAudioHandset];

ashirkhanpm commented 2 years ago
Screenshot 2022-09-17 at 7 25 30 PM

I got this error ["Thread 7: EXC_BAD_ACCESS (code=1, address=0x3)"] when I call the switchToEarPice method at line no 3

ziyiz-amzn commented 2 years ago

does it work without the filter? is it contains the list of all devices ?

ashirkhanpm commented 2 years ago

@ziyiz-amzn yes, it work without filter, I think the AudioDevices array contains all devices because I can able to print AudioDevices[0] and AudioDevices[1] separately in NSLog

ziyiz-amzn commented 2 years ago

Then you may need to debug your filters.