Reputation: 1577
I have got a Angular 5 project. Its getting file paths from database and play them. But some of my filenames are like '[Teknik-Servis%3A905533837273]_05533837273-630_20181005104235(160133).wav' and including special characters like :,[] % etc.. So when i play this file im getting Uncaught (in promise) DOMException: Failed to load because no supported source was found. error at console. %3A is ':' character so when i call url maybe browser try to change it so getting error. But there is no problem while playing this filename like '[630 Selcuk]_630-140_20180919082432(76142).wav' Is there any way to play this audio files that got special characters (%3A,%5B) at their filenames?
My audio play function;
playAudio(filepath) {
let filename= filepath.replace(/^.*(\\|\/|\:)/, '');
console.log(filepath);
if (this.audio.src.replace(/^.*(\\|\/|\:)/, '') == filename) {
// if(this.audio.src==filepath){
if (this.audio.paused)
this.audio.play();
else
this.audio.pause();
}
else {
this.audio.pause();
this.audio = new Audio();
this.audio.src = filepath;
this.audio.load();
this.audio.play();
}
}
Upvotes: 1
Views: 1015
Reputation: 2053
You need to encode your file names with encodeURIComponent()
for example.
this.audio.src = encodeURIComponent(filepath);
Upvotes: 1