8000 Get audio sources list and change localstream audio · Issue #395 · flutter-webrtc/flutter-webrtc · GitHub
[go: up one dir, main page]

Skip to content

Get audio sources list and change localstream audio #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LucMoreau33560 opened this issue Oct 27, 2020 · 15 comments
Closed

Get audio sources list and change localstream audio #395

LucMoreau33560 opened this issue Oct 27, 2020 · 15 comments
Labels

Comments

@LucMoreau33560
Copy link

Hello,

Is it possible to list all audio sources : headphones, speaker, bluetooth, ... available on the device ?
An how can I change from one to another during a call ?

Thank you,
Luc

@wer-mathurin
Copy link
Contributor
wer-mathurin commented Oct 28, 2020

You can use:
navigator.mediaDevices.getSources()

after you authorize the user to access media.

Look for device of kind == 'audiooutput'

After you can specify the deviceid is in the constraint.

Sorry I'm on my mobile, but I hope it give you enough direction

If you are using the web implementation, it will only work if you are using the master branch. See bug #367

@LucMoreau33560
Copy link
Author

Hello,
Thank you, I'm using ios and android implementation.
I have to test more. For the moment the getSources() gives me 2 cameras and one audio (even if I plug a headphone, the audio source label becomes "écouteurs" (headphones in French). I was thinking that there will be 2 audio sources if I plug headphones. I don't have any bluetooth devices, I will get one tomorrow to test with a bluetooth device.

Another point, you said I have to specify the device id in the constraint, does it mean that I can't change audio source during the call ?

Thanks,
Luc

@gbmiranda
Copy link

I have the same problem, I can't see the audio outputs or disable the ear speaker

@LucMoreau33560
Copy link
Author

Hello,
I have tested my devices (iphone 7 and Huawei P8 Lite) with a Jabra bluetooth headset BT2045.
The very simple code I wrote to list media devices is :
final mediaDevices = navigator.mediaDevices;
var devices = await mediaDevices.getSources();
for (int i=0; i<devices.length; i++){
print(devices[i]);
}

The result is the same on Android and iOS, and the result is the same if the bluetooth headset is connected or not :
IOS :
flutter: {deviceId: com.apple.avfoundation.avcapturedevice.built-in_video:0, label: Back Camera, facing: back, kind: videoinput}
flutter: {deviceId: com.apple.avfoundation.avcapturedevice.built-in_video:1, label: Front Camera, facing: front, kind: videoinput}
flutter: {deviceId: com.apple.avfoundation.avcapturedevice.built-in_audio:0, label: iPhone Micro, facing: , kind: audioinput}

ANDROID (All permissions (AUDIO, BLUETOOTH, ...) are present in AndroidManifest.xml) :
I/flutter (21295): {kind: videoinput, facing: back, label: Camera 0, Facing back, Orientation 90, deviceId: 0}
I/flutter (21295): {kind: videoinput, facing: front, label: Camera 1, Facing front, Orientation 270, deviceId: 1}
I/flutter (21295): {kind: audioinput, facing: , label: Audio, deviceId: audio-1}

Do I forgot something to have all audio devices listed ?

@gbmiranda
Copy link

And to access the two native speakers of the devices? How do I do?

I have a problem that I can't disable the ear speaker and use only the main one.

@LucMoreau33560
Copy link
Author
LucMoreau33560 commented Nov 9, 2020

Hello gbmiranda,
On my phones, when I simply call someone with the vanilla phone functionnality, I can select my audio sources bewteen phone ear speaker, the main speaker and bluetooth device.
If I plug a wire headset, the phone ear speaker is replaced by the wire headset. I can not choose between them. I have to unplug the wire headset if I want to use the phone ear speaker again.

Maybe I misunderstand your question, you just want to enable or disable the speaker.
In that case, I am using the following 3 lines of code to enable the speaker :
_remoteRenderer.srcObject.getAudioTracks()[0].enabled = true;
_remoteRenderer.srcObject.getAudioTracks()[0].setVolume(5);
_remoteRenderer.srcObject.getAudioTracks()[0].enableSpeakerphone(true);

@wer-mathurin
Copy link
Contributor

@LucMoreau33560

You can look at the latest commit on the master.
I implemented a Helper class to start implementing basing functionality, change camera and so on.
Maybe we can add change audio source in the future. Feel free to provide a PR to add that :-)

For the web implementation, is a little bit easier, since we can provide a different constraints. Look at the code on switchCamera().

We can probably do the same thing for changeAudioOutput.

@wer-mathurin
Copy link
Contributor
wer-mathurin commented Nov 30, 2020

Related to #375 for the web implementation

@stale
Copy link
stale bot commented Feb 7, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Feb 7, 2021
@stale stale bot closed this as completed Feb 14, 2021
@thammaknot
Copy link

Is still feature (list all audio sources) still not working on mobile?

@wer-mathurin do you still have the link to the commit you referred to above?

You can look at the latest commit on the master.
I implemented a Helper class to start implementing basing functionality, change camera and so on.
Maybe we can add change audio source in the future. Feel free to provide a PR to add that :-)

Thank you

@wer-mathurin
Copy link
Contributor

The helper class is:
flutter-webrtc/lib/src/helper.dart

Make sure you have accept the permission request for accessing camera and microphone before enumerating devices.

@thammaknot
Copy link

Thank you. Sorry I just got a chance to revisit this again.

I was hoping to see how you enumerate camera devices so that I could adapt the implementation for audio outputs. However, I couldn't find it in helper.dart; I probably misinterpreted your comment.

Would you be able to help point me in the right direction?
Starting from being able to enumerate all audio devices... do we need to start with native implementation?

@ycherniavskyi
Copy link
Member

Have you try/look at something like audio_session plugin.

I am not sure that this functionality must be implemented within flutter-webrtc. If you have arguments/thoughts why must - let's discuss.

@thammaknot
Copy link

Thank you! I will check it out.

I don't think the webrtc constraint is a must.

@thammaknot
Copy link

I was able to the the audio input device IDs. However, webrtc's getUserMedia() does not seem to respect the device ID specified in the constraints.

Does FlutterWebRTC support selecting audio input by device IDs?
I tried hardcoding the sourceId, but the audio seems to always come from the default mic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
0