Examples / StreamMgr

Right-click to copy examples to your workspace


Wherein we show how to stream internet audio streams into your audio graph.

In this simple example, we use the combination of StreamMgr and Hz.StreamIn to deliver audio into your soundscapes. A more elaborate example can be found here.

Example

let ascene = await Ascene.BeginFiber(this);
console.log("Audio scene is ready to go.");
let dac = ascene.GetDAC();
let anode = ascene.NewAnode("Hz.StreamIn");
ascene.Chain(anode, dac);
await ascene.Sync();

let [host, stream] = ["https://live.radioradicale.it", "/live.mp3"];
StreamMgr.AudioStreamOpen(host, stream, anode.GetId())
.then((ret) =>
{
    console.log(`open returned ${JSON.stringify(ret)}`);
    if(ret.tid != null)
    {
        // Listen for 20 seconds. Streaming may take a while to
        // get going.
        setTimeout(async () =>
        {
            console.log(`closing ${ret.tid}`);
            StreamMgr.AudioStreamClose(ret.tid);        
            await Aengine.Close();
        }, 20000);
    }
});
home .. topics .. interface .. reference .. examples .. tipjar