使用Angular/Javascript在Edge中播放WAV音频文件
我在Angular中有以下代码来播放上传的WAV文件:使用Angular/Javascript在Edge中播放WAV音频文件,javascript,angular,microsoft-edge,wav,Javascript,Angular,Microsoft Edge,Wav,我在Angular中有以下代码来播放上传的WAV文件: <input #fileImportInput (change)="fileChangeListener($event)" /> <audio #myAudio controls controlsList="nodownload"> <source src="" /> </audio> audioElement: HTMLAudioElement; @ViewChild('myAudio
<input #fileImportInput (change)="fileChangeListener($event)" />
<audio #myAudio controls controlsList="nodownload">
<source src="" />
</audio>
audioElement: HTMLAudioElement;
@ViewChild('myAudio', { static: true }) myAudio: any;
ngOnInit() {
this.audioElement = this.myAudio.nativeElement;
}
fileChangeListener(files: any): void {
const inputFile = files.target.files[0];
if (window.URL && window.URL.createObjectURL) {
this.audioSrcURL = window.URL.createObjectURL(inputFile);
this.audioElement.src = this.audioSrcURL;
}
}
audioElement:HTMLAudioElement;
@ViewChild('myAudio',{static:true})myAudio:any;
恩戈尼尼特(){
this.audioElement=this.myAudio.nativeElement;
}
fileChangeListener(文件:任意):无效{
const inputFile=files.target.files[0];
if(window.URL&&window.URL.createObjectURL){
this.audioSrcURL=window.URL.createObjectURL(inputFile);
this.audioElement.src=this.audioSrcURL;
}
}
上述方法适用于Chrome和Firefox,但不适用于Edge 44(18)。如何在Edge中播放WAV文件?尝试使用F12开发者工具检查Edge浏览器中是否有错误,以及音频源是否设置成功。如果没有错误且音频资源设置成功,请尝试调用以播放音频 此外,这里有一个使用JavaScript上传回放音频文件的示例,您可以参考它:
<input type="file" id="input" />
<audio id="sound" controls="controls">
<source src="" />
</audio>
<script type="text/javascript">
var input = document.getElementById('input');
input.onchange = function (e) {
var sound = document.getElementById('sound');
sound.src = URL.createObjectURL(this.files[0]);
// not really needed in this exact case, but since it is really important in other cases,
// don't forget to revoke the blobURI when you don't need it
sound.onend = function (e) {
URL.revokeObjectURL(this.src);
}
}
</script>
var input=document.getElementById('input');
input.onchange=函数(e){
var sound=document.getElementById('sound');
sound.src=URL.createObjectURL(this.files[0]);
//在这种情况下确实不需要,但在其他情况下,这非常重要,
//当你不需要的时候,别忘了撤销blobURI
sound.onend=函数(e){
revokeObjectURL(this.src);
}
}