Jitsi - Play WAV file during a call - if possible mix with sound

I configure Jitsi to play a Wav file when making a call.

I ran into difficulties in this, and would appreciate it if you could help me.

I can switch the data source before starting the call using the custom AudioFileMediaDevice and including it in the CallPeerMediaHandler.

But I am having problems replacing the data source when making a call.

==================================================== ============

I tried the following, but could not get it to work.

1) I tried to get the source data source of the device and added the source URL of the wav file using the addInDataSource method. Does not work.

DataSource dataSource = device.createOutputDataSource(); DataSource fileDataSource = Manager.createDataSource(new URL("file://resources/sounds/Sample.wav")); ((AudioMixingPushBufferDataSource)dataSource).addInDataSource(fileDataSource); 

2) I tried adding a custom Capture device and switching it, but it doesn’t work either:

 CaptureDeviceInfo2 fileDevice = new CaptureDeviceInfo2("Recorded Audio 1", fileDataSource.getLocator(), null, null, null, null); ((MediaServiceImpl) LibJitsi.getMediaService()) .getDeviceConfiguration().getAudioSystem().setDevice(AudioSystem.DataFlow.CAPTURE, fileDevice, false); 

This works for playback, but not as a capture device.

3) I even tried to add a new audio system with a playback device as a file data source, but this also does not work.

==================================================== ============

I am new to libjitsi, so I have a hard time trying to decipher what is happening. Any directions on how to resolve this would be great.

+8
java file device audio jitsi
source share
2 answers

I made a playback sound when called using this code:

 public void startPlaying(CallPeer callPeer, DataSource soundDataSource) throws OperationFailedException { assert callPeer instanceof CallPeerSipImpl; CallPeerSipImpl cp = (CallPeerSipImpl) callPeer; AudioMediaStreamImpl audioMediaStream = (AudioMediaStreamImpl) cp.getMediaHandler().getStream(MediaType.AUDIO); AudioMediaDeviceSession deviceSession = audioMediaStream.getDeviceSession(); assert deviceSession != null; assert deviceSession.getDevice() instanceof AudioMixerMediaDevice; AudioMixerMediaDevice dev = (AudioMixerMediaDevice) deviceSession.getDevice(); dev.getAudioMixer().addInDataSource(soundDataSource); } 

Please note that AudioMixerMediaDevice.getAudioMixer () has personal access in libjitsi, so I made it public and recompiled.

0
source share

I needed to play an audio file during a call, but only on the far side of the call. Therefore, I played a little with the example of stokitos and modified it for my needs. If someone needs it, here is what I did:

 private void playAudioFromDataSource(final CallPeerSipImpl callPeer, final DataSource audioDataSource, final MediaDirection direction) { final CallPeerMediaHandlerSipImpl mediaHandler = callPeer.getMediaHandler(); final AudioMediaStreamImpl audioMediaStream = (AudioMediaStreamImpl) mediaHandler.getStream(AUDIO); final AudioMediaDeviceSession deviceSession = audioMediaStream.getDeviceSession(); if (null != deviceSession) { if (RECVONLY == direction) { // plays audio local only: deviceSession.addPlaybackDataSource(audioDataSource); } else { final AudioMixerMediaDevice mediaDevice = (AudioMixerMediaDevice) deviceSession.getDevice(); final AudioMixer audioMixer = getAudioMixer(mediaDevice); if (null != audioMixer) { if (SENDONLY == direction) { // plays audio remote only: audioMixer.getLocalOutDataSource().addInDataSource(audioDataSource); } else if (SENDRECV == direction) { // plays audio on both sides of call (local and remote): audioMixer.addInDataSource(audioDataSource); } } } } } private AudioMixer getAudioMixer(final AudioMixerMediaDevice device) { try { final Method privateGetAudioMixerMethod = device.getClass().getDeclaredMethod("getAudioMixer"); privateGetAudioMixerMethod.setAccessible(true); final Object audioMixerObject = privateGetAudioMixerMethod.invoke(device, (Object[]) null); return (AudioMixer) audioMixerObject; } catch (final Exception e) { log.error("Could not get AudioMixer", e); } return null; } 

NOTE. I was looking for reflection to get the private AudioMixer object. I admit that this is not the cleanest approach, but it works. :)

0
source share

All Articles