app.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. var wavesurfer;
  3. // Init & load
  4. document.addEventListener('DOMContentLoaded', function () {
  5. var options = {
  6. container : '#waveform',
  7. waveColor : 'violet',
  8. progressColor : 'purple',
  9. loaderColor : 'purple',
  10. cursorColor : 'navy',
  11. plugins: [
  12. WaveSurfer.timeline.create({
  13. container: '#wave-timeline'
  14. })
  15. ]
  16. };
  17. if (location.search.match('scroll')) {
  18. options.minPxPerSec = 100;
  19. options.scrollParent = true;
  20. }
  21. if (location.search.match('normalize')) {
  22. options.normalize = true;
  23. }
  24. // Init wavesurfer
  25. wavesurfer = WaveSurfer.create(options);
  26. /* Progress bar */
  27. (function () {
  28. var progressDiv = document.querySelector('#progress-bar');
  29. var progressBar = progressDiv.querySelector('.progress-bar');
  30. var showProgress = function (percent) {
  31. progressDiv.style.display = 'block';
  32. progressBar.style.width = percent + '%';
  33. };
  34. var hideProgress = function () {
  35. progressDiv.style.display = 'none';
  36. };
  37. wavesurfer.on('loading', showProgress);
  38. wavesurfer.on('ready', hideProgress);
  39. wavesurfer.on('destroy', hideProgress);
  40. wavesurfer.on('error', hideProgress);
  41. }());
  42. wavesurfer.load('../media/demo.wav');
  43. });