Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

wavesurfer加载网络资源波形不出现

用wavesurfer绘制波形图加载网络资源波形不出现,加载本地相对路径的就一切正常
打印错误出现 Error: HTTP error status: 0
image.png

刚开始声音都播放不了,加入了backend:'MediaElement'这个配置声音可以正常出现,波形还是加载不了
### 相关代码
this.bottomWavesurfer=WaveSurfer.create({

                    barWidth:3,
                    container:'#audioPlay',
                    waveColor: "#464C55",
                    progressColor: "#FFA600",
                    cursorColor: "#fff",
                    backend:'MediaElement',
                    height: 40,
                    xhr:{
                        mode:"no-cors"
                    }
                });
                this.bottomWavesurfer.load(this.playData.master);
                // this.bottomWavesurfer.load("./static/obj_wo3DlMOGwrbDjj7DisKw_4442982362_0e99_5b56_f906_136dfc1bcf0f129963c8df412f561626.mp3")
                // this.bottomWavesurfer.load('http://replacebeat.com/static/aaa.mp3')
                var that=this;
                this.bottomWavesurfer.on('ready',()=>{
                    console.log('加载完成');
                    that.isplay=true;
                    that.bottomWavesurfer.play();
                })
                this.bottomWavesurfer.on('error',err=>{
                    console.warn(err);
                })
                
                this.bottomWavesurfer.on('finish',()=>{
                    that.isplay=false;
                })

该怎么解决


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

个人理解:其实根本原因还是音频链接跨域请求的影响,拿不到音频数据,就无法解析波形

 xhr:{
      mode:"no-cors"
     }

这东西虽然表面上在F12下看不到报跨域请求的错(在该模式下允许浏览器发送本次跨域请求),但是不能访问响应返回的内容。所以还是叫后端允许cors吧或者vue配代理


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...