Comments (4)
I never tried that, due to lack of time. As far as I know, the native WebRTC implementation does not catch a device change, even if you enumerate the devices after one is (dis)connected. The implementation with (dis)connected callbacks is my own. Thus its a bit hard to tell device module to switch the device.
The next thing to consider are the media tracks managed by the peer connection, since each track (mic/cam) is bound to a device. You can switch tracks or the sources of tracks, but if the source is not updated it obviously goes wrong.
I would handle this issue with a low priority.
from webrtc-java.
Thank you for your quick response!
I want to share the method that I tried. Maybe it will be useful.
I found on the Internet that it is possible to replace a track by calling the sender.replaceTrack method and specify AudioTrack as an input parameter. In the browser implementation WebRTC, it looks something like this::
//...
var audioTrack = stream.getAudioTracks()[0];
var sender = pc.getSenders().find(function(s) {
return s.track.kind == audioTrack.kind;
});
sender.replaceTrack(audioTrack);
//...
I tried to do something similar in the DeviceChangeListener.deviceConnected method. I re-created AudioTrack and tried to replace the track. This did not give a positive result. Code on kotlin::
connection.senders.find {
it.track.kind.equals(MediaStreamTrack.AUDIO_TRACK_KIND)
}?.let { rtcSender ->
val audioOptions = AudioOptions().apply {
this.noiseSuppression = true
this.echoCancellation = true
}
val audioSource = peerConnectionFactory?.createAudioSource(audioOptions)
val audioTrack = peerConnectionFactory?.createAudioTrack("audioTrack", audioSource)
rtcSender.replaceTrack(audioTrack)
}
I also made an attempt to replace
rtcSender.replaceTrack(audioTrack)
on
rtcSender.track.dispose() // otherwise, the removeTrack method will hang
connection.removeTrack(rtcSender)
connection.addTrack(audioTrack, listOf("stream"))
also to no avail
from webrtc-java.
Hi @Stasyanych,
this should work at runtime when the media is already flowing and you send/receive audio:
AudioDevice captureDevice; // Get desired device.
AudioDevice playbackDevice; // Get desired device.
AudioDeviceModule deviceModule = new AudioDeviceModule();
// For sending audio.
deviceModule.setRecordingDevice(captureDevice);
deviceModule.initRecording();
// For receiving audio.
deviceModule.setPlayoutDevice(playbackDevice);
deviceModule.initPlayout();
PeerConnectionFactory factory = new PeerConnectionFactory(deviceModule);
// Initialize PeerConnection and establish connection.
// Change audio recording and playback device at runtime.
// For sending audio.
deviceModule.stopRecording();
deviceModule.setRecordingDevice(newRecordingDevice);
deviceModule.initRecording();
deviceModule.startRecording();
// For receiving audio.
deviceModule.stopPlayout();
deviceModule.setPlayoutDevice(newPlaybackDevice);
deviceModule.initPlayout();
deviceModule.startPlayout();
from webrtc-java.
Thank you! I will definitely check it out.
from webrtc-java.
Related Issues (20)
- glibc version too higher HOT 4
- constructor_magic.h File not found HOT 1
- Ununderstandible behaviour of data channel
- Crash on closing data channel HOT 1
- How to create a local MediaStream? HOT 1
- DtmfSender implementation? HOT 1
- Transfer existing RTP Stream
- Fatal error in audio_send_stream.cc HOT 6
- Disable Media Input Source of Peer. HOT 2
- The IP address of the candidate that you received through the onIceCandidate callback function in the PeerConnectionObserver interface is 0.0.0.0
- Receiving media data from client HOT 3
- if can? GainControl provide kAgcModeAdaptiveAnalog mode? HOT 1
- mvn install failed HOT 8
- Support linux-aarch64 HOT 1
- The offer I created cannot be saved, why is that?
- How to use WebRTC-Java to implement the server to push the UDP message on multiple browsers
- when demo will be publishes HOT 1
- Video cannot be obtained from the SRS service HOT 2
- Error in C++ Standard Library usage.
- Load library 'webrtc-java' failed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webrtc-java.