I'm in the process of learning Angular and am working on a website I've always wanted to make, something very similar to that of Internet Radio.
I'm mainly a .NET developer so all this stuff is still a bit alien to me, but I'm learning. Currently I'm in the process of making a system so I can retrieve the metadata from such internet radios - for example, the title of the current song.
Since most of these stations are broadcast via Icecast/Shoutcast, I need to send a GET request which includes the header "Icy-MetaData"
with a value of 1
.
This should return a response with a header containing icy-metaint
and a value containing data how large each chunk of audio is, after this chunk it will return a byte containing the size of the metadata string. Then this process needs to repeat, at least that's my understanding of it.
I've been running into issues with CORS but I think I've bypassed it via launching my browser with security features turned off, as suggested here.
Here's a stripped down version of that I currently have;
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
@Component({
selector: 'app-radio-player',
templateUrl: './radio-player.component.html',
styleUrls: ['./radio-player.component.scss']
})
export class RadioPlayerComponent implements OnInit {
constructor(private http: HttpClient) {}
ngOnInit(): void {
var headers = new HttpHeaders({
'Access-Control-Allow-Headers':'Request-Header, Response-Header',
'Access-Control-Allow-Methods':'POST, GET',
'Access-Control-Allow-Origin': '*',
'Access-Control-Expose-Headers':'Response-Header',
'Icy-MetaData': '1'
});
this.http.get("http://stream.antenne.de/antenne", {headers, observe: 'response'}).subscribe(resp => {
console.log(resp.headers.get("icy-metaint"));
});
}
}
I've tried this via Postman and it works as expected, however when I try this locally via serve - the console is empty.
I'm fairly sure I'm either doing something wrong, or CORS preventing me from testing this. I understand why CORS exists, but I am a bit at a loss as to how to properly test stuff as this without CORS getting in the way.
So any suggestions would be much appreciated.
Edit:
On second thought, I don't think what I'm trying to do is possible with just Angular. The stuff I'm trying to get is a continuous connection, which is probably why I don't get any console output, because it technically never finishes.
I was able to connect to the adress, get the response headers and read the data via C#.
So I would need some kind of backend service which retrieves this data and sends it to Angular.
This got a lot more complicated than I thought it would be so I'll probably just put this on the backburner for now.