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 40f19e0f385f82727a5c6e354fda1040592f7c0b..95321893eb650f584c203bef93b94c4f8dbc3ef1 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 0000000000000000000000000000000000000000..59033fa6b16daefdcc6b8c81f24f0acbb1dac0ad --- /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() +}