123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 'use strict';
- // Create an instance
- var wavesurfer;
- // Init & load audio file
- document.addEventListener('DOMContentLoaded', function () {
- // Init
- wavesurfer = WaveSurfer.create({
- container: document.querySelector('#waveform'),
- waveColor: '#A8DBA8',
- progressColor: '#3B8686',
- backend: 'MediaElement',
- plugins: [
- WaveSurfer.regions.create({
- regions: [
- {
- start: 0,
- end: 5,
- color: 'hsla(400, 100%, 30%, 0.1)'
- }, {
- start: 10,
- end: 100,
- color: 'hsla(200, 50%, 70%, 0.1)'
- }
- ]
- }),
- WaveSurfer.timeline.create({
- container: '#timeline'
- })
- ]
- });
- // Load audio from URL
- wavesurfer.load('../media/demo.wav');
- // Zoom slider
- var slider = document.querySelector('[data-action="zoom"]');
- slider.value = wavesurfer.params.minPxPerSec;
- slider.min = wavesurfer.params.minPxPerSec;
- slider.addEventListener('input', function () {
- wavesurfer.zoom(Number(this.value));
- });
- // Play button
- var button = document.querySelector('[data-action="play"]');
- button.addEventListener('click', wavesurfer.playPause.bind(wavesurfer));
- });
|