我正在尝试在我的 vue 前端应用程序中使用 wavesurfer.js。从后端获取到音频文件的链接后,出现此错误:
wavesurfer.js?8896:5179 Uncaught (in promise) TypeError: Cannot read property 'isPaused' of null
at WaveSurfer.empty (wavesurfer.js?8896:5179)
at WaveSurfer.load (wavesurfer.js?8896:4852)
at _callee$ (GameScreen.vue?dcce:42)
at tryCatch (runtime.js?96cf:63)
at Generator.invoke [as _invoke] (runtime.js?96cf:293)
at Generator.eval [as next] (runtime.js?96cf:118)
at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
at _next (asyncToGenerator.js?1da1:25)
at eval (asyncToGenerator.js?1da1:32)
at new Promise (<anonymous>)
这是我在 vue 组件中使用的代码
<script>
import axios from 'axios';
import wavesurfer from 'wavesurfer.js';
export default {
name: 'GameScreen',
data(){
return {
isLoading: true,
}
},
mounted(){
this.initAudio();
},
methods: {
initAudio(){
axios.get('http://localhost:6060/track').then( async (response) => {
console.log(response.data);
const waveform = new wavesurfer({
container: this.$refs.wave,
color: 'violet',
backend: 'MediaElement'
});
await waveform.load(response.data);
await waveform.on('ready', () => {
this.isLoading = false;
//waveform.play();
});
console.log(waveform);
});
}
}
}
</script>
代码中是否有任何错误或我可以做些什么来解决这个问题?
更新
问题已结束,我想发布解决方案但不可能。无论如何,问题在于我在实例化库时犯的错字。我忘记调用 create
方法。要正确实例化 WaveSurfer,语法是 new WaveSurfer.create({...})
而不仅仅是 new WaveSurfer({})
谢谢大家的帮助。