我正在使用 wavesurfer-js angular 6 应用程序,播放器在没有控件的情况下打开,并且出现错误说:
未捕获的类型错误:无法读取未定义的属性“wavesurfer”
这是我的 ts 代码:
import { Component, AfterViewInit, OnInit } from '@angular/core';
import { MatBottomSheetRef } from '@angular/material';
import WaveSurfer from 'wavesurfer.js';
import VideojsWavesurfer from 'videojs-wavesurfer';
import SpectrogramPlugin from
'wavesurfer.js/dist/plugin/wavesurfer.spectrogram.min.js';
@Component({
selector: 'app-audio-page',
templateUrl: './audio-page.component.html',
styleUrls: ['./audio-page.component.scss'],
})
export class AudioPageComponent implements OnInit {
public wavesurfer: WaveSurfer;
constructor(private bottomSheetRef:
MatBottomSheetRef<AudioPageComponent>){ }
ngOnInit() {
let audiofile =
"https://ia902606.us.archive.org/35/items/shortpoetry_047_librivox
/song_cjrg_teasdale_64kb.mp3"
this.wavesurfer = WaveSurfer.create({
container: '#waveform',
height:100,
waveColor : 'red',
scrollParent: true,
progressColor: 'purple',
plugins: [
SpectrogramPlugin.create({
container: "#wave-spectrogram"
})
]
});
this.wavesurfer.load(audiofile);
this.wavesurfer.on('ready', function () {
this.wavesurfer.play();
});
}
}
和我的 HTML:
<div id="waveform"></div>
<div id="wave-spectrogram"></div>