Javascript Audio Player Sync Progress Bar Background Color or Image to currentTime

Javascript Audio Player Sync Progress Bar Background Color or Image to currentTime

I have a javascript audio player that is able to track the timing or stay in sync while the song is playing and when the user clicks on the progress bar, the slider handle will set the value of the "audio.currentTime".

Here is the actual audio player that I'm currently testing. Please take a quick look: http://newsletters.aaronestebancoaching.com/test1/1.html

But what I'm trying to do is create either a background color or background image that will also move along the progress bar to sync up with the currentTime as well.

Here is what I have so far:

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. #audio-container{
  9. position:relative;
  10. margin:auto;
  11. width:320px;
  12. height:90px;
  13. background:orange;
  14. border:2px solid black;
  15. margin-top:25px;
  16. }
  17. #play{
  18. background:url(images/play-sprite.png);
  19. background-position:0px 0px;
  20. width:60px;
  21. height:60px;
  22. float:left;
  23. cursor:pointer;
  24. margin-left:5px;
  25. }
  26. #play:hover{
  27. background-position:120px 0px;
  28. }
  29. #play:active{
  30. background-position:60px 0px;
  31. }
  32. #pause{
  33. background:url(images/pause-sprite.png);
  34. background-position:0px 0px;
  35. width:60px;
  36. height:60px;
  37. float:left;
  38. cursor:pointer;
  39. }
  40. #pause:hover{
  41. background-position:120px 0px;
  42. }
  43. #pause:active{
  44. background-position:60px 0px;
  45. }
  46. #audio-slider{
  47. position:relative;
  48. -webkit-appearance:none;
  49. appearance:none;
  50. width:98%;
  51. background:darkorange;
  52. border:1px solid brown;
  53. height:10px;
  54. border-radius:10px;
  55. outline:none;
  56. cursor:pointer;
  57. margin-left:2px;
  58. margin-top:5px;
  59. }
  60. #audio-slider::-webkit-slider-thumb{
  61. -webkit-appearance:none;
  62. appearance:none;
  63. width:10px;
  64. height:20px;
  65. border:1px solid black;
  66. background:brown;
  67. }
  68. #fill-bar{
  69. position:absolute;
  70. height:10px;
  71. border-top-left-radius:10px;
  72. border-bottom-left-radius:10px;
  73. margin-left:2px;
  74. margin-top:5px;
  75. width:0px;
  76. background:red;
  77. bottom:14px;
  78. left:1px;
  79. }
  80. </style>
  81. </head>
  82. <body>
  83. <div id="audio-container">
  84. <div id="play" onclick="play()"></div>
  85. <div id="pause" onclick="pause()"></div>
  86. <input type="range" id="audio-slider" min="0" value="0" step="1" onchange="seek()">
  87. <div id="fill-bar"></div>
  88. </div>
  89. </body>
  90. <script type="text/javascript">
  91. var audio = new Audio();
  92. var audioSlider = document.getElementById("audio-slider");
  93. var fillbar = document.getElementById("fill-bar");
  94. audio.src = "music/Song2.mp3";
  95. function play(){
  96. audio.play();
  97. }
  98. function pause(){
  99. audio.pause();
  100. }
  101. //sync the slider handle with the currentTime
  102. setInterval(updateSongSlider, 1000);
  103. function updateSongSlider(){
  104. var c = Math.round(audio.currentTime);
  105. audioSlider.value = c;
  106. fillbar.style.width = c + "px";
  107. var d = audio.duration
  108. audioSlider.setAttribute("max", d);
  109. }
  110. //set the currentTime to match users click on the progress bar
  111. function seek(){  
  112. audio.currentTime = audioSlider.value;
  113. play();
  114. }
  115. </script>
  116. </html>

How would I create the background color or image to sync up with the currentTime? The problem is that the #fill-bar div is covering up the input slider and doesn't allow for me to click and set the currentTime properly on the progress bar.

What would be a better way of doing this? I'd still like to stick with the input slider if possible. Thanks!

I appreciate a good starting point.