Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <h1>Créer une playlist avec balise audio HTML (javascript)</h1> 
<p>Dans ces exemples, la balise audio est mise dans le Html. Nous ne faisons que lui assigner une chanson à jouer.<br>
  Chaque élement de la playlist sassigne la musique à jouer et met audio en pause ou à play.  
  <br>Musique de chez universal-soundbank.com</p>
<div class="mise-en-page">
  <div class="bloc-mise-en-page"> 
    <div class="playwgd" id="playerone">
      <audio autoplay controls ></audio>
      <ul class="play-list">
        <li data-sound="16062.mp3"><i class="material-icons">play_circle_outline</i><span>Légion Etrangère : Voix-choeurs</span></li>
        <li data-sound="16061.mp3"><i class="material-icons">play_circle_outline</i><span>Légion Etrangère : J'avais un camarade  </span></li>
        <li data-sound="16063.mp3"><i class="material-icons">play_circle_outline</i><span>Légion étrangère : tiens voila du boudin</span></li>
      </ul>
    </div> 
  </div> 
  <div class="bloc-mise-en-page"> 
    <div class="playwgd"  id="playertwo">
      <audio id="player" autoplay controls ></audio>
      <ul  class="play-list">
        <li data-sound="13819.mp3"><i class="material-icons">play_circle_outline</i><span>W.A MOZART -  Requiem en D Mineur - Introitus</span></li>
        <li data-sound="13820.mp3"><i class="material-icons">play_circle_outline</i><span>W.A MOZART - Requiem en D Mineur - Kyrie</span></li>
        <li data-sound="13823.mp3"><i class="material-icons">play_circle_outline</i><span>W.A MOZART - Requiem en D Mineur - Sanctus </span></li>
        <li data-sound="13824.mp3"><i class="material-icons">play_circle_outline</i><span>W.A MOZART - Requiem en D Mineur - Benedictus </span></li>
        <li data-sound="13825.mp3"><i class="material-icons">play_circle_outline</i><span>W.A MOZART - Requiem en D Mineur - Agnus Dei</span></li>
        <li data-sound="13825llll.mp3"><i class="material-icons">play_circle_outline</i><span>W.A MOZART - Requiem en D Mineur - ERROR 404</span></li>
      </ul>
    </div> 
  </div> 
</div> 
<hr>
<div class="mise-en-page-lien">
  <div class="bloc-mise-en-page bloc-lien">
    <h2>Liens utiles Javascript </h2>
    <ul>
      <li><a href="https://www.zonecss.fr/cours-css-javascript/les-selecteurs-javascript.html#zmbrwm00000.codepen" target="_blank">Listes propriétés et méthodes javascript de la balise video (audio).</a></li>
      <li><a href="https://outils-javascript.aliasdmc.fr/evenements-video-html5-javascript.php#zmbrwm00000.codepen" target="_blank">Ecoutes des événements javascript de la balise video (audio) HTML5.</a></li>
    </ul>
    <h2>Liens codepen liés</h2>
    <ul>
      <li><a href="https://codepen.io/Zonecss/pen/GdVrVg" target="_blank">Jouer un son en Javascript (100% js)</a></li> 
       <li><a href="https://codepen.io/Zonecss/pen/jpKQPg" target="_blank">Créer son propre player avec une playlist (HTML /Javascript)</a></li> 
      <li><a href="https://codepen.io/Zonecss/pen/oQgxGp" target="_blank">Leçon de Piano (Javascript)</a></li> 
    </ul>
  </div>
  <div class="bloc-mise-en-page bloc-lien bloc-sites">
    <h2>Sites</h2>
    <ul>
      <li><a href="https://www.zonecss.fr/#zmbrwm00000.codepen" target="_blank" title="Glossaire CSS">Zone CSS</a></li>
      <li><a href="http://www.aliasdmc.fr/#zmbrwm00000.codepen" target="_blank" title="Glossaire HTML/JAVASCRIPT">Zone (X)HTML</a></li>
      <li><a href="https://web-color.aliasdmc.fr/#zmbrwm00000.codepen" target="_blank" title="Couleurs pour le WEb (#,rgb,hsl)">Couleurs Web</a></li>
      <li><a href="https://outils-css.aliasdmc.fr/#zmbrwm00000.codepen" target="_blank">Outils CSS</a></li>
      <li><a href="https://outils-javascript.aliasdmc.fr/#zmbrwm00000.codepen" target="_blank">Outils Javascript</a></li>
    </ul>
  </div>
</div>

            
          
!

CSS

            
              
.play-list,.play-list li{
  padding:0;margin:0;
  list-style:none;
}

.playwgd{display:inline-block;width:450px}
.playwgd audio{width:100%}

.play-list .material-icons,
.play-list li span{vertical-align:middle;}

.play-list li span{line-height: 25px;}
.play-list li{
  display: block;
  padding:5px;
  cursor:pointer;
  border-bottom:1px solid rgb(146, 146, 157);
  cursor:pointer;
  -khtml-user-select : none;
  -webkit-user-select : none;
  -moz-user-select : -moz-none;
  -ms-user-select : none;
  user-select : none;
}
.play-list li:hover{ 
  background-color:#efeff2;
}
.play-list li.selected{ 
  background-color: #c5dad5
}
 
            
          
!

JS

            
              /* //////////////////////////////////////////////
Plus d'informations liées à la solution  : 
////////////////////////////////////////////// */

/*
Toutes le fonctions ci-dessous peuvent être optimisées
elles sont même volontairement non optimisées
Elles sont là juste pour vous présenter le concept à vous de les améliorer 
*/

/*
 * @param String  sIdPlayer         valeur de l'attribut Id element contenant
 *                                  une balise audio 
 *                                  et classe play-list ses fils directs déclenche l'audio
 * @param Boolean bStopOtherParam   true = met en pause les autres playlists liées
 *                                  false par défaut
 **/
function PlayList(sIdPlayer, bStopOtherParam){
  this.bStopOther = bStopOtherParam == undefined? false : bStopOtherParam;
  this.sName = sIdPlayer;
  this.oPlayer = null;
  this.oPlaylist = null;
  this.oChanson = null;
  this.getaPlayers = function(){ 
    return window['aPlayers'] != undefined? window['aPlayers']:null; 
  }//fct
  this.resetSlection = function (){ 
    if(this.oChanson != null){
      this.oPlayer.pause();
      this.setLine(this.oChanson, this.oPlayer.paused, true);
    }//if
  }//fct
  this.stopOther = function (){ 
    var aPlayers  = this.getaPlayers();
    if(this.bStopOther == true && aPlayers != null){
      for(var i = 0 ; i < aPlayers.length; i++){
        if(aPlayers[i] != this){
          aPlayers[i].resetSlection();
        }//if      
      }//for
    }//iff
  }//fct
  this.playChanson = function (oEvent){ 
    var oItem = oEvent.currentTarget, sSound = oItem.getAttribute('data-sound'),
        sUrl = "http://s1download-universal-soundbank.com/mp3/sounds/"+sSound ;
    /* A vous de gérer la manière de recupere l'ur du son */
    this.stopOther();
    if(this.oChanson == oItem){ 
      if(this.oPlayer.paused==true){
        this.oPlayer.play();
      }else{
        this.oPlayer.pause();
      }//else
      this.setLine(this.oChanson, this.oPlayer.paused, true);
    }else{
      this.oPlayer.src = sUrl;
      this.oPlayer.play();
      this.setLine(this.oChanson, true, false);
      this.setLine(oItem, false, true);
    } //else
    this.oChanson = oItem;
  }//fct
  this.setLine = function (oItem, bPause, bSelected, bError){
    if(oItem == null){return}
    if(bError == undefined ){bError = false}
    var sSelected = "selected",
        sPause = 'pause_circle_outline', 
        sPlay  = 'play_circle_outline',
        sError  = 'block',
        oIcone = oItem.children[0];
    if(bSelected == true){ 
      oItem.classList.add(sSelected);
    }else{ 
      oItem.classList.remove(sSelected);
    } //else
    if(bError == true ){
      oIcone.innerHTML= sError ;
      return;
    }//if
    if(bPause == true){
      oIcone.innerHTML= sPlay ;  
    }else if(bPause == false){
      oIcone.innerHTML= sPause ;  
    }else{
      oIcone.innerHTML= bPause ;  
    }//else
    
  }//fct

  this.playerEvent = function(oEvent){
    if(this.oChanson != null && (oEvent.type == 'play' || oEvent.type == 'pause' || oEvent.type == 'playing')){
      this.setLine(this.oChanson, this.oPlayer.paused, true);
    }else if(oEvent.type == 'error'){ 
      this.setLine(this.oChanson, this.oPlayer.paused, false, true);
      this.oChanson  = null;
    }else if(oEvent.type == 'waiting'){ 
      this.setLine(this.oChanson, 'cloud_queue', true);
    } 
  }//fct
  
  this.init = function(){
    if(this.sName ==''){ return false; } 
    var oPlayerWdg = document.getElementById(this.sName);
    if(oPlayerWdg == null){ return false; }
    var oMyWdg = this,
        aPlaylist = null,
        oTmpAudio = oPlayerWdg.getElementsByTagName('audio'),
        oTmpList = oPlayerWdg.getElementsByClassName('play-list');
    if(oTmpAudio.length == 0 || oTmpList.length == 0 ){ return false;}
    this.oPlayer   =  oTmpAudio[0];
    this.oPlaylist = oTmpList[0]; 
    if(this.bStopOther){
      window['aPlayers']= window['aPlayers']==undefined?[]:window['aPlayers'];
      window['aPlayers'].push(this);
    }
    aPlaylist = this.oPlaylist.children; 
    for(var i = 0; i < aPlaylist.length; i++){ 
      aPlaylist[i].addEventListener('click', function(oEvent){oMyWdg.playChanson(oEvent)});
      aPlaylist[i].setAttribute("data-position",i);  
    } 
    this.oPlayer.addEventListener('play', function(oEvent){oMyWdg.playerEvent(oEvent)});
    this.oPlayer.addEventListener('pause', function(oEvent){oMyWdg.playerEvent(oEvent)});
    this.oPlayer.addEventListener('error', function(oEvent){oMyWdg.playerEvent(oEvent)});
    this.oPlayer.addEventListener('waiting', function(oEvent){oMyWdg.playerEvent(oEvent)});
     this.oPlayer.addEventListener('playing', function(oEvent){oMyWdg.playerEvent(oEvent)}); 
  }
  this.init();
}//fct
 
document.addEventListener('DOMContentLoaded',function(){
  var oMyPlayListOne = new PlayList("playerone", true);
  var oMyPlayListTwo = new PlayList("playertwo", true);
});
            
          
!
999px

Console