play connected sound from sound file

This commit is contained in:
Daniel Gultsch 2024-01-17 13:53:12 +01:00
parent d31b24d05a
commit 7f9d836f1a
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 17 additions and 3 deletions

View file

@ -20,6 +20,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.util.MainThreadExecutor; import eu.siacs.conversations.ui.util.MainThreadExecutor;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager; import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager;
@ -33,6 +34,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class CallIntegration extends Connection { public class CallIntegration extends Connection {
private static final int DEFAULT_VOLUME = 80;
private final Context context;
private final AppRTCAudioManager appRTCAudioManager; private final AppRTCAudioManager appRTCAudioManager;
private AudioDevice initialAudioDevice = null; private AudioDevice initialAudioDevice = null;
private final AtomicBoolean initialAudioDeviceConfigured = new AtomicBoolean(false); private final AtomicBoolean initialAudioDeviceConfigured = new AtomicBoolean(false);
@ -43,6 +48,7 @@ public class CallIntegration extends Connection {
private Callback callback = null; private Callback callback = null;
public CallIntegration(final Context context) { public CallIntegration(final Context context) {
this.context = context.getApplicationContext();
if (selfManaged()) { if (selfManaged()) {
setConnectionProperties(Connection.PROPERTY_SELF_MANAGED); setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
this.appRTCAudioManager = null; this.appRTCAudioManager = null;
@ -297,7 +303,9 @@ public class CallIntegration extends Connection {
@Override @Override
public void onStateChanged(final int state) { public void onStateChanged(final int state) {
Log.d(Config.LOGTAG, "onStateChanged(" + state + ")"); Log.d(Config.LOGTAG, "onStateChanged(" + state + ")");
if (state == STATE_DISCONNECTED) { if (state == STATE_ACTIVE) {
playConnectedSound();
} else if (state == STATE_DISCONNECTED) {
final var audioManager = this.appRTCAudioManager; final var audioManager = this.appRTCAudioManager;
if (audioManager != null) { if (audioManager != null) {
audioManager.executeOnMain(audioManager::stop); audioManager.executeOnMain(audioManager::stop);
@ -305,9 +313,15 @@ public class CallIntegration extends Connection {
} }
} }
private void playConnectedSound() {
final var mediaPlayer = MediaPlayer.create(context, R.raw.connected);
mediaPlayer.setVolume(DEFAULT_VOLUME / 100f, DEFAULT_VOLUME / 100f);
mediaPlayer.start();
}
public void success() { public void success() {
Log.d(Config.LOGTAG, "CallIntegration.success()"); Log.d(Config.LOGTAG, "CallIntegration.success()");
final var toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, 100); final var toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, DEFAULT_VOLUME);
toneGenerator.startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375); toneGenerator.startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
this.destroyWithDelay(new DisconnectCause(DisconnectCause.LOCAL, null), 375); this.destroyWithDelay(new DisconnectCause(DisconnectCause.LOCAL, null), 375);
} }
@ -323,7 +337,7 @@ public class CallIntegration extends Connection {
public void error() { public void error() {
Log.d(Config.LOGTAG, "CallIntegration.error()"); Log.d(Config.LOGTAG, "CallIntegration.error()");
final var toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, 80); final var toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, DEFAULT_VOLUME);
toneGenerator.startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375); toneGenerator.startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
this.destroyWithDelay(new DisconnectCause(DisconnectCause.ERROR, null), 375); this.destroyWithDelay(new DisconnectCause(DisconnectCause.ERROR, null), 375);
this.destroyWith(new DisconnectCause(DisconnectCause.ERROR, null)); this.destroyWith(new DisconnectCause(DisconnectCause.ERROR, null));

Binary file not shown.