Streaming tracks
Learn how to create streaming tracks in your Yoto app.
A playlist can contain “streaming” tracks, where the audio is streamed from a URL when the track is played.
This is useful if you want to create dynamic content that changes all the time, like weather updates.
How to create a streaming track
The key difference is in the track object, which needs the following:
- the
trackUrlproperty should be set to the URL that hosts the audio - the
typeproperty should be set tostream - the
formatproperty should be set to the format of the stream, for examplemp3oraac
Here is an example of how to create a streaming playlist:
Show complete example
export const createStreamingPlaylist = async ({
title = "Test Streaming Playlist",
accessToken,
}) => {
const chapters = [
{
key: "01",
title: title,
overlayLabel: "1",
tracks: [
{
key: "01",
type: "stream",
format: "mp3",
title: title,
trackUrl: "https://yoto.dev/audio/autumn-3.mp3",
display: {
icon16x16: "yoto:#ZuVmuvnoFiI4el6pBPvq0ofcgQ18HjrCmdPEE7GCnP8",
},
},
],
display: {
icon16x16: "yoto:#ZuVmuvnoFiI4el6pBPvq0ofcgQ18HjrCmdPEE7GCnP8",
},
},
];
const content = {
title: title,
content: { chapters },
metadata: { description: "Streaming playlist" },
};
const createResponse = await fetch("https://api.yotoplay.com/content", {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(content),
});
const result = await createResponse.json();
console.log("Streaming playlist created successfully!");
return result;
};