From 86931f168cfe9fdafa7340bba556b9ad65b180d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de> Date: Thu, 8 Dec 2022 10:56:02 +0100 Subject: [PATCH] Try converting to endianness --- .../briar/desktop/utils/AudioUtils.kt | 8 ++++- .../briar/desktop/TestPlayAudio.kt | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/TestPlayAudio.kt diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/utils/AudioUtils.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/utils/AudioUtils.kt index 40f19e0f38..95321893eb 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/utils/AudioUtils.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/utils/AudioUtils.kt @@ -20,6 +20,7 @@ package org.briarproject.briar.desktop.utils import org.briarproject.briar.desktop.utils.ResourceUtils.getResourceAsStream import java.io.BufferedInputStream +import javax.sound.sampled.AudioFormat import javax.sound.sampled.AudioSystem import javax.sound.sampled.Clip @@ -29,8 +30,13 @@ object AudioUtils { val resourceStream = getResourceAsStream(name) ?: return null val bufferedStream = BufferedInputStream(resourceStream) // add buffer for mark/reset support val audioInputStream = AudioSystem.getAudioInputStream(bufferedStream) + val f = audioInputStream.format + val audioInputStream2 = AudioSystem.getAudioInputStream( + AudioFormat(f.encoding, f.sampleRate, f.sampleSizeInBits, f.channels, f.frameSize, f.frameRate, true), + audioInputStream + ) val sound = AudioSystem.getClip() - sound.open(audioInputStream) + sound.open(audioInputStream2) return sound } diff --git a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/TestPlayAudio.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/TestPlayAudio.kt new file mode 100644 index 0000000000..59033fa6b1 --- /dev/null +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/TestPlayAudio.kt @@ -0,0 +1,30 @@ +/* + * Briar Desktop + * Copyright (C) 2021-2022 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop + +import org.briarproject.briar.desktop.notification.SoundNotificationProvider +import org.briarproject.briar.desktop.utils.AudioUtils +import org.briarproject.briar.desktop.utils.AudioUtils.play +import javax.sound.sampled.AudioFormat +import javax.sound.sampled.AudioSystem + +fun main() { + val sound = AudioUtils.loadAudioFromResource("/audio/notification.wav") ?: throw Exception() + sound.play() +} -- GitLab