Skip to content
The Yoto Developer Challenge is on, with $10,000 to win!

Streaming tracks

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.

The key difference is in the track object, which needs the following:

  • the trackUrl property should be set to the URL that hosts the audio
  • the type property should be set to stream
  • the format property should be set to the format of the stream, for example mp3 or aac

Here is an example of how to create a streaming playlist:

export const createStreamingPlaylist = async ({
title = "Test Streaming Playlist",
streamUrl = "https://yoto.dev/autumn-3.mp3",
accessToken,
}) => {
const chapters = [
{
key: "01",
title: title,
overlayLabel: "1",
tracks: [
{
key: "01",
type: "stream",
format: "mp3",
title: title,
trackUrl: streamUrl,
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;
};