/ Examples / MusicAPI / Loader

Right-click to copy examples to your workspace


You'd like your scripts to have access to local and internet-based files.

Note that we present multiple examples in this project.

Overview

The Loader API is a JavaScript API for asynchronously loading or caching files. Lua programmers can find similar capabilities in the Async module.

SampleMgr is a higher-level interface tailored to helping you manage and reference internet-based audio sample files.

Examples

fetchurl.jsk

Use can use FetchURL to load internet JSON and XML files into your projects.

let newquote = await FetchURL("https://zenquotes.io/api/random", "json");
let f = newquote[0];
console.log(`zenquote ${f.h}`);


let dom = await FetchURL("https://feeds.bbci.co.uk/news/world/rss.xml", "xml");
for(let item of Array.from(dom.querySelectorAll("item")).slice(0,5))
{
    console.log(item.querySelector("title").textContent);
}

let eth = await FetchURL("https://api.coinbase.com/v2/prices/ETH-USD/spot", "json");
// expect; {"data":{"amount":"2207.995","base":"ETH","currency":"USD"}}%                                         
console.log(`1 ETH costs ${eth.data.amount} ${eth.data.currency}`);

let btc = await FetchURL("https://api.coinbase.com/v2/prices/BTC-USD/spot", "json");
// expect; {"data":{"amount":"2207.995","base":"BTC","currency":"USD"}}%                                         
console.log(`1 BTC costs ${btc.data.amount} ${btc.data.currency}`);

Note that internet based services fluxuate in their availabilty and can often require entitlement codes. Caveat emptor.

dumpplugins.js

You can access the contents of local workspace files with FetchWSFile.

/**
 * This exmaple uses FetchWSFile to access the file produced when you
 * scan plugins.  Note that this information is already avaiable via
 * via the Anodes MusicAPI.
 */
let db = await FetchWSFile("_plugins/anode.yaml", "yaml");
if(db)
{
    for(let plug of db.ClapPlugins)
        console.log(`${plug.name} has ${plug.params.length} params`);
}

See Also

MusicAPI/Loader

home .. topics .. interface .. reference .. examples .. tipjar