A
A
alekseyizmaylov2022-02-03 06:51:16
JavaScript
alekseyizmaylov, 2022-02-03 06:51:16

How to play sound in browser?

Hello,
I'm trying to autoplay sound when opening a site,
I googled several options, none of them work (Chrome browser),
below is a code example - how can I still do this?

And if you need a sound when you click a button on the site, too, how to do it?

Dear Admin. please do not delete this question with the wording that all this
can be found through the search - everything that is there does not work)

<audio src="click.mp3" autoplay="autoplay"></audio>
 
или так 
<audio autoplay>
    <source src="click.mp3" type="audio/mpeg">
</audio>

или так
<audio src='click.mp3' autoplay='autoplay' loop='loop'></audio>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nadim Zakirov, 2022-02-03
@zkrvndm

Display a notification that the site uses cookies and add a button to close this notification. When you press the button, you use the event from it to activate the audio.

A
alekssamos, 2022-02-03
@alekssamos

Previously, yes, it was possible to automatically play, but now the browser developers have removed this feature. Only if clicked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question