learning python
learning python

Reputation: 39

Audio won't autoplay

<!DOCTYPE html>
<html>
<body>
<audio controls autoplay>
  <source src="Rick Roll.mp3" type="audio/mpeg">
</audio>

</body>
</html>

For some reason, it won't play automatically. Is it because the file is too big?

Upvotes: 0

Views: 281

Answers (3)

Youssouf Oumar
Youssouf Oumar

Reputation: 46261

That is because non muted autoplayed media are blocked by browsers. Here is what MDN says about it:

As a general rule, you can assume that media will be allowed to autoplay only if at least one of the following is true:

  • The audio is muted or its volume is set to 0
  • The user has interacted with the site (by clicking, tapping, pressing keys, etc.)
  • If the site has been allowlisted; this may happen either automatically if the browser determines that the user engages with media frequently, or manually through preferences or other user interface features
  • If the autoplay feature policy is used to grant autoplay support to an and its document.

Add the muted like so:

<audio controls autoplay muted>
  <source src="Rick Roll.mp3" type="audio/mpeg">
</audio>

Upvotes: 0

Mah Es
Mah Es

Reputation: 630

Media like video or audio will not play automatically anymore. This is a security thing. In order to play the media, user must interact with the page, like with a click.

Upvotes: 1

Arman Ebrahimi
Arman Ebrahimi

Reputation: 2317

There is a space in your src that is invalid.

<source src="Rick Roll.mp3" type="audio/mpeg">

Try for fix that(if is this):

<source src="RickRoll.mp3" type="audio/mpeg">

Upvotes: 0

Related Questions