我正在尝试为我的应用程序中的音频和视频内容生成一个波形,目前使用的是angular 6和TypeScript。我可以用wavesurfer.js制作波形,但是我不能让时间线插件工作。在我的angular.json中有这样的脚本
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js",
"node_modules/moment/min/moment.min.js",
"node_modules/wavesurfer.js/dist/wavesurfer.js",
"node_modules/wavesurfer.js/dist/plugin/wavesurfer.timeline.js"
]在我的component.ts文件中,我有如下代码
declare var WaveSurfer;
declare var TimelinePlugin;
export class TranscriptComponent implements OnInit {
ngAfterViewInit() {
this.wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: 'violet',
progressColor: 'purple',
cursorColor: '#d9fb36',
normalize: true,
skipLength: 15,
hideScrollbar: true,
backend: 'MediaElement',
plugins: [
TimelinePlugin.create({
// plugin options ...
})
]
});
}如果没有-插件,我可以得到波形,但是如果我尝试添加插件,我会得到错误"TimelinePlugin is undefined“。可以告诉我如何使用这些插件使用typescript。举个例子就好了。
发布于 2019-06-12 19:20:17
我通过显式地将我需要的插件的路径添加到angular.json中的“脚本”数组(architect和Test.),使其正常工作(经过反复试验):
"scripts": [
"./node_modules/wavesurfer.js/dist/wavesurfer.js",
"./node_modules/wavesurfer.js/dist/plugin/wavesurfer.regions.js"
],然后我将插件导入到带有音频播放器的组件中:
import * as WaveSurfer from 'wavesurfer.js';
import * as WaveSurferRegions from 'wavesurfer.js/dist/plugin/wavesurfer.regions.js';并初始化播放器:
ws: any;
ngOnInit() {
this.ws = WaveSurfer.create({
container: document.querySelector('#player_waveform'),
backend: 'MediaElement',
plugins: [
WaveSurferRegions.create({
regions: [
{
start: 1,
end: 3,
color: 'hsla(400, 100%, 30%, 0.5)'
}, {
start: 5,
end: 7,
color: 'hsla(200, 50%, 70%, 0.4)'
}
]
})
]
});
}我也对npm做了一些修改,但很难说这是否是让它工作的原因。我确实安装了较新的wavesurfer.js和wavesurfer。我删除了wavesurfer,这可能会有帮助?
https://stackoverflow.com/questions/52129733
复制相似问题