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.
How to create a streaming track
Section titled “How to create a streaming track”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 tostream
- the
format
property should be set to the format of the stream, for examplemp3
oraac
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;};