I've recently played around with Javascript and the Subsonic REST API.
Have someone on this forum successfully been able to use the range of Subsonic API functions using Javascript?
I have no problems accessing the API to retrieve index, search for songs or similar. This is easily done using XMLHttpRequest. For instance:
- Code: Select all
[var url = "...../rest/getIndexes.view?v=1.2.0&c=myapp";
var client = new XMLHttpRequest();
client.open("GET", url, false, user, pass); // With HTTP Basic Authentication
client.send(null);
// process XML response
But how do I go about using the parts of the Subsonic API that fetches binary data? For a simple example lets refer to fetching album cover art using "...../rest/getCoverArt.view"
According to the Subsonic API spec a valid cover art request would look like this:
- Code: Select all
"...../rest/getCoverArt.view?v=1.2.0&c=myapp&id=123456789"
and sent with coded "Authorization" header containing user and pass
If I go about fetching binary data using XMLHttpRequest the Subsonic server responds just fine but as far as I know there is no way I can reinterpret and force this data into DOM element.
A more natural use case would instead be to update the src attribute of the DOM for an image element such as:
- Code: Select all
<img src='' id='coverimage'/>
and let the element download the image from the URL and populate the area. But with this approach I can not make it work.
How the heck would I be able to authorize (following the HTTP Authentication as with the XMLRequest example) fetching data from the Subsonic server via an element URL request?
It seems to me the API is somewhat limited? Or am I just interpreting it wrong?
Any ideas appreciated, I'm totally stuck.
Thanks,
Petter
