[英]Wavesurfer.js : How to display custom markers?
对于我的新网页,我需要集成一个波形音频播放器,并且正在使用waveurfer.js包。 正如他们所说的要在波形的不同位置添加自定义标记时,直到现在我还没有开始工作。 我的代码如下:
'use strict';
// Create an instance
var wavesurfer = Object.create(WaveSurfer);
// Init & load audio file
document.addEventListener('DOMContentLoaded', function () {
var options = {
container : document.querySelector('#waveform'),
waveColor : 'violet',
progressColor : 'purple',
loaderColor : 'purple',
cursorColor : 'navy'
};
if (location.search.match('scroll')) {
options.minPxPerSec = 100;
options.scrollParent = true;
}
if (location.search.match('normalize')) {
options.normalize = true;
}
// Init
wavesurfer.init(options);
// Load audio from URL
wavesurfer.load('example/media/demo.wav');
// Regions
if (wavesurfer.enableDragSelection) {
wavesurfer.enableDragSelection({
color: 'rgba(0, 255, 0, 0.1)'
});
}
});
// Play at once when ready
wavesurfer.on('ready', function () {
wavesurfer.play();
wavesurfer.mark({id: 'chorus', position: 10})
});
并在控制台中收到如下错误:
Uncaught TypeError: undefined is not a function
有人可以为此建议解决方案吗?
我不知道是否找到解决方法,但可以将其标记为区域。 在下面添加而不是您的区域代码:
// Region
if (wavesurfer.enableDragSelection) {
region = wavesurfer.addRegion({
start: 5,
end: 5 + 0.5,
resize: false,
drag: false,
color: 'rgba(255,0,0, 0.7)'
});
}
您可以通过在初始化音频后调用ready来使此工作正常进行
wavesurfer.on('ready', function () {
// Adding a couple of pre-defined regions
wavesurfer.addRegion({
start: 5, // time in seconds
end: 8, // time in seconds
color: 'hsla(100, 100%, 30%, 0.1)'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.