简体   繁体   English

Wavesurfer.js:如何显示自定义标记?

[英]Wavesurfer.js : How to display custom markers?

For my new webpage I need to integrate a wave formed audio player and I am using wavesurfer.js package. 对于我的新网页,我需要集成一个波形音频播放器,并且正在使用waveurfer.js包。 As they are saying about adding custom markers at different positions in wave form, I didn't get that working till now. 正如他们所说的要在波形的不同位置添加自定义标记时,直到现在我还没有开始工作。 My code is as below: 我的代码如下:

'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})
});

And getting an error as below in console: 并在控制台中收到如下错误:

Uncaught TypeError: undefined is not a function 

Can anybody suggest a solution for this ? 有人可以为此建议解决方案吗?

I dunno if you find some solution, but you can mark as region. 我不知道是否找到解决方法,但可以将其标记为区域。 add below instead of your region code: 在下面添加而不是您的区域代码:

// Region
if (wavesurfer.enableDragSelection) {
  region = wavesurfer.addRegion({
    start: 5,
    end: 5 + 0.5,
    resize: false,
    drag: false,
    color: 'rgba(255,0,0, 0.7)'
  });
}

You can get this working by calling on ready after the initialization of audio 您可以通过在初始化音频后调用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM