Skip to content

Instantly share code, notes, and snippets.

@katspaugh
Created August 11, 2024 12:21
Show Gist options
  • Save katspaugh/48950705f7944e2406b9e41c9e0152cc to your computer and use it in GitHub Desktop.
Save katspaugh/48950705f7944e2406b9e41c9e0152cc to your computer and use it in GitHub Desktop.
// Regions click through
import WaveSurfer from 'wavesurfer.js'
import RegionsPlugin from 'wavesurfer.js/dist/plugins/regions.esm.js'
// Initialize the Regions plugin
const regions = RegionsPlugin.create()
// Create a WaveSurfer instance
const wavesurfer = WaveSurfer.create({
container: document.body,
waveColor: 'rgb(200, 0, 200)',
progressColor: 'rgb(100, 0, 100)',
url: '/examples/audio/audio.wav',
plugins: [regions],
})
// Create some regions at specific time ranges
wavesurfer.on('ready', () => {
// Regions
regions.addRegion({
start: 2,
end: 8,
content: 'Click through',
color: 'rgba(0, 0, 100, 0.5)',
})
const noClickRegion = regions.addRegion({
start: 11,
end: 14,
content: 'No click through',
color: 'rgba(100, 0, 100, 0.5)',
})
noClickRegion.on('click', e => e.stopPropagation())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment