Brianmuks
Brianmuks

Reputation: 49

playing multiple audio files

I am trying to create a playlist with the code below but I seem to be getting some errors. Firebug is saying that the play() is not a function. please help I have spent half of my day trying to find a solution. Here is my code:

<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script>     

         var current, playlist;
         current = 0;
         function() {
             current++;
             var songs = Array("en_ra1.mp3", "en_ra2.mp3", "en_ra3.mp3", "en_ra0.mp3");
             playlist = songs.length;
             if (current == playlist) {
               //do nothing or stop
             } else {
               this.playOptions = document.getElementById("audio").src = songs[current];
               this.playOptions.play();
             }
         }
  </script>
  </head>
<body>
<audio id="audio" onended="loadplaylist()" src="ny_option1.mp3"  controls  ></audio>

Note:when I include the autoplay attribute it's works just fine despite the error showing in firebug console.

Upvotes: 0

Views: 1586

Answers (1)

kevmc
kevmc

Reputation: 1294

I'm not seeing where you declare the loadplaylist function, presumably a typo

in your function you are setting this.playOptions to the string returned from the array, not the player, I think your function should read something like this:

 function loadplaylist() {
         current++;
         var songs = Array("en_ra1.mp3", "en_ra2.mp3", "en_ra3.mp3", "en_ra0.mp3");
         playlist = songs.length;
         if (current == playlist) {
           //do nothing or stop
         } else {
           this.playOptions = document.getElementById("audio");
           this.playOptions.src = songs[current];
           this.playOptions.play();
         }
     }

Upvotes: 2

Related Questions