radiomanifest.js/doc/tutorials/quickstart.md

56 lines
1.9 KiB
Markdown
Raw Normal View History

2022-01-30 14:18:34 +01:00
Using radiomanifest is pretty simple. In an ideal usecase, you can easily do this:
```javascript
2023-09-14 01:07:07 +02:00
const radiomanifest = require("radiomanifest");
const radio = radiomanifest.get("http://myradio.com/");
console.log(radio.getName());
2022-01-30 14:18:34 +01:00
```
Now we have `radio`, a {@link Radio} object, which can be seen as the "center" of our data. From here, we can
2022-01-30 14:38:43 +01:00
get more data.
2022-01-30 14:18:34 +01:00
## Streaming
2023-09-14 01:07:07 +02:00
The first thing we could want to do is just to _play_ the radio. Let's use the {@link RadioStreaming#pickURLs
2022-01-30 14:38:43 +01:00
RadioStreaming.pickURLs} method then
2022-01-30 14:18:34 +01:00
```javascript
2023-09-14 01:07:07 +02:00
var streaming = radio.getStreaming();
var urls = await streaming.pickURLs();
console.log(urls);
2022-01-30 14:18:34 +01:00
```
and here we go! This is a list of URLs that the radio is indicating to us as their preferred ones. Why not a
single one? Well, this could include different servers, so that the client itself can act as load-balancers.
## Shows
Another nice thing you might want to do, is to display a list of all the shows that the radio is broadcasting.
Our {@link Radio} keeps track of those, and for each show we can have useful metadata. See {@link RadioShow}
for more details.
```javascript
2023-09-14 01:07:07 +02:00
var shows = radio.getShows();
console.log(shows.map((s) => s.getName()));
2022-01-30 14:18:34 +01:00
```
2023-09-14 01:07:07 +02:00
2022-01-30 14:38:43 +01:00
## Schedule
```javascript
2023-09-14 01:07:07 +02:00
const show = radio.getShowAtTime();
2022-01-30 14:38:43 +01:00
if (show !== null) {
2023-09-14 01:07:07 +02:00
console.log(show.getName());
2022-01-30 14:38:43 +01:00
} else {
2023-09-14 01:07:07 +02:00
console.log("Nothing special going on right now, sorry");
2022-01-30 14:38:43 +01:00
}
```
{@link Radio#getShowAtTime getShowAtTime} is a shortcut, but using {@link Radio#getSchedule} you'll get a nice
{@link RadioSchedule}, which has many useful methods to get meaningful information about what's going on right
now and {@link RadioSchedule#getNextShow what will go on next}
2022-01-30 14:18:34 +01:00
## Conclusions
I hope this tutorial helped you get your feet wet. Hopefully, using radiomanifest you'd be able to create
2023-09-14 01:07:07 +02:00
great webapps that work on _any_ webradio (well, any webradio that supports radiomanifest, at least).