Cherche code pour musique HTML

Fermé
Diva - 5 févr. 2020 à 20:06
dugenou Messages postés 6087 Date d'inscription mercredi 19 janvier 2005 Statut Contributeur Dernière intervention 30 juillet 2021 - 5 févr. 2020 à 22:01
Bonjour, je cherche un code Html qui met des musique.ogg aléatoire sur une page



Configuration: Windows / Chrome 79.0.3945.130
A voir également:

1 réponse

dugenou Messages postés 6087 Date d'inscription mercredi 19 janvier 2005 Statut Contributeur Dernière intervention 30 juillet 2021 1 451
5 févr. 2020 à 22:01
Bonsoir,

Ce sujet a été traité sur ce forum :
https://forums.commentcamarche.net/forum/affich-34359151-une-solution-pour-des-musiques-aleatoires-mp3-sur-une-page-web

Il faut juste modifier le script pour utiliser la balise <audio> en HTML5 :

<script type="text/javascript">
var sound1="audio/fichier1.ogg"
var sound2="audio/fichier2.ogg"
var sound3="audio/fichier3.ogg"
var sound4="audio/fichier4.ogg"
var sound5="audio/fichier5.ogg"
var sound6="audio/fichier6.ogg"
var sound7="audio/fichier7.ogg"
var x=Math.round(Math.random()*7)
if (x==0) x=sound1
else if (x==1) x=sound2
else if (x==2) x=sound3
else if (x==3) x=sound4
else if (x==5) x=sound5
else if (x==6) x=sound6
else x=sound7
document.write("<audio controls autoplay width='140' height='60'> <source src='"+x+""+"' type='audio/ogg' /></audio>")
</script>


0