app.js 1.4 KB

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