как воспроизводить аудио файл бек springBooth фронт angular
рест
@GetMapping("/statistic/audioPreview")
public void getAudioPreview(@RequestParam String pathFile, HttpServletResponse response, HttpServletRequest request) {
this.convertFile.convertAndSend(pathFile, response, request);
}
//перед тем как сунуть в респонс аудио мы его конвертируем
public void convertAndSend(String pathFile, HttpServletResponse response, HttpServletRequest request) {
File file = new File(environment.getProperty("app.fullrecord.dir") + "/" + pathFile);
log.info("запрос на получение файла");
log.info(file.getAbsolutePath());
if (file.exists()) {
log.debug("существует gsm файл");
File newCallFile = new File("/tmp/" + Arrays.stream(pathFile.split("/"))
.reduce((first, second) -> second).orElse("tmp").replace(".gsm", ".wav"));
try {
String cmd = "sox " + file.getAbsolutePath() +
" -e signed-integer -b 16 " + newCallFile.getAbsolutePath();
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
response.setContentType("audio/wav");
response.setHeader("Content-Disposition", "inline; filename=file.wav");
response.setContentType("audio/wav");
FileUtils.copyFile(newCallFile, response.getOutputStream());
} catch (Exception e) {
log.error("Удаленный хост принудительно разорвал существующее подключение при прослушивании монолога");
} finally {
if (newCallFile.delete()) {
log.debug("файл " + newCallFile.getName() + " удалён");
}
}
}
}
//фронт ангуляр
loadAudio(pathFile: string, idx: number) {
let options: HttpParams = new HttpParams();
if (pathFile) {
options = options.set('pathFile', pathFile);
}
console.log(pathFile);
return this.http.get(this.url + '/audioPreview', {
params: options,
headers: {Authorization: `Bearer ${this.authService.getCurrentToken()}`},
observe: 'response'
}).subscribe( res => {
if (res.body) {
console.log(idx.toString());
console.log(res.body);
const url = window.URL.createObjectURL(res.body);
const audio = new Audio();
audio.controls = true;
audio.loop = true;
audio.preload = 'none';
audio.id = 'field-audio' + idx;
audio.src = url;
audio.setAttribute('controlsList', 'nodownload');
console.log('document.getElementById(idx.toString()) = ' + document.getElementById(idx.toString()))
document.getElementById(idx.toString()).append(audio);
}
// audio.play();
},
error => {
console.log('download error:', JSON.stringify(error));
},
() => {
console.log('Completed file download.');
}
);
}
в консоле браузера я вижу что срабатывает errorResponse console.log('download error:', JSON.stringify(error)); и при этом в консоле браузера отображается что файл приходит т.е. почему приходит еррор респонс? если у него статуст 200?
если через html просто ссылу подставлять на рест контроллер то всё пашет, но мне необходимо ещё в хедеры крепить токен