Audio sound on button press

Does anyone have an idea of how to easily play a short sound effect when pressing a button?

Here is solution for my case:

Audio element without controls:

`@Tag(“audio”)
@Slf4j
public class Audio extends Component {

public Audio() {
    getElement().setAttribute("controls", false);
}

public void setSource(String audioFileName) {

    var stream = new StreamResource("audio-file", () -> {

        File file = null;
        try {
            file = new ClassPathResource("META-INF/resources/" + audioFileName).getFile();
            byte[] data = Files.readAllBytes(file.toPath());
            return new ByteArrayInputStream(data);
        } catch (IOException e) {
            log.error(e.toString());
            throw new RuntimeException(e);
        }

    }
    )
            .setContentType("audio/mpeg"); // For MP3

    getElement().setAttribute("src", stream);
}

public void play() {
    getElement().callJsFunction("play");
}

}`

And usage

`
audio = new Audio();
audio.setSource(“barcode-beep.mp3”);

    add(audio);`

Did you try executeJs(“this.play();”); instead?

Will try.