Cherche code pour musique HTML

Diva -  
dugenou Messages postés 6262 Statut Contributeur -
Bonjour, je cherche un code Html qui met des musique.ogg aléatoire sur une page

Configuration: Windows / Chrome 79.0.3945.130

1 réponse

  1. dugenou Messages postés 6262 Statut Contributeur 1 455
     
    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