I have a loop that makes a table, and each of the rows have an audio file, the audio playing has an ID of "audio"+i to give unique ids to the different audios.
I'm making a progress bar but I need the "i" variable to determine which of the audios the progress bar should act on, if I replace "i" with a number, then it works. I just haven't found a way to get the "i" variable.
HTML/PHP where the loop and audio are:
for($i=0; $i<$count; $i++){
$res = mysqli_fetch_array($result);
echo('<tbody id="tbody">
<tr>
<audio id="audio'.$i.'" src="mp3/'.$res["song_artist"].'-'.$res["song_title"].'.mp3">
<td><button class="playbutton" id="playbtn'.$i.'" onclick="playStop('.$i.')">▷</button></td>
<td><img class="songimg" src="getimage.php?id='.$res["song_id"].'"/> </td>
<td>'.$res["song_title"].'</td>
<td>'.$res["song_artist"].'</td>
<td>'.$res["song_genre"].'</td>
<td>'.$res["song_album_name"].'</td>
</tr>
</tbody>');
}
}
Progress bar code where I need the "i" variable:
var progressbar = document.getElementById("progress-bar");
progressbar.onclick = function(e) {
var audio = document.getElementById("audio"+i);
audio.currentTime = ((e.offsetX/progressbar.offsetWidth) * audio.duration);
}
}
Thank you in advance.