A playlist player

Integrate a playlist player

You have a Streamlike playlist and want your visitors to watch it back-to-back like a TV series: a player, the video list next to it, autoplay of the next video, and a share link that resumes playback at the right spot. That’s exactly what `generatePlaylistPlayer` does—it’s been available in the JavaScript SDK since version 3.5.0. One function, one container, and the rest is just configuration.

Two lines to get started

Install the SDK, specify a container, and provide your playlist ID.

At this point, you already have a working player: media is fetched in the order of the playlist, the first track is loaded, the list is displayed on the right with thumbnails and durations, the previous/next buttons are active, and the next video starts playing as soon as the previous one ends.

Here’s what this code looks like on the Streamlike demo playlist:

Loading the demo…

The demo is set to display four videos per page, so that the “Load More” button appears below the list.

The player also accepts a view (viewId), a company (companyId), or directly an array of media files that you’ve already retrieved (medias)—which is handy if your page calls the web service for other reasons. The web service’s sorting and filtering parameters remain accessible via playlistParams.

No installation required

The SDK has no dependencies: the published files can be used directly in a browser, from an npm CDN such as jsDelivr or unpkg. No installation or build steps are required—making it easy to set up a prototype, a standalone page, or a site that you don’t compile.

If your page cannot use ES modules—such as a CMS or an older template—a second version exposes the entire SDK via a global variable:

A tip: Always pin a specific version. With @latest, a future release could change the behavior of pages you no longer control. And keep in mind that a public CDN introduces a third party into your pages: integrations that can’t accept this will go through npm and serve the SDK from their own domain.

Choosing What Information to Display

This is the setting that makes all the difference depending on the context: a news page doesn’t display the same metadata as a training portal. The “info” option lists what appears while the page is being viewed.

OptionDefaultContent
titletrueThe media name
positiontrueThe position in the playlist, formatted as “3 / 12”
durationtrueThe media duration
currentTimefalseReading position, updated in real time
playlistNamefalseThe playlist name
descriptionfalseThe media description
releaseDatefalseThe release date
releaseTimefalseThe release time (hours and minutes)
viewsfalseThe number of views
keywordsfalseThe standard keywords

The locale option controls the formatting of dates, times, and view counts. Interface text, on the other hand, is replaced using labels.

The same logic applies to list items using listItem: thumbnail, number, title, duration, and description. And if you want the thumbnails to animate on hover, pass them the interactive preview options:

Long playlists

A playlist of 300 videos doesn’t load all at once. The player fetches ten at a time, then expands the list as you watch: by the time you reach the ninth video, the next ten are already on their way. A “More” button remains available below the list as long as there are videos to load, and the counter shows your progress—“20 / 330.”

No settings are required for this to work. If you’d prefer to load everything at once—for a short playlist or a page that needs to be complete immediately—increase the page size:

A caveat regarding long lists: animated thumbnails download the storyboard for each video as soon as it’s displayed. For a list of a few dozen entries, the benefit is worth the cost; for three hundred, that adds up to just as many requests. The static thumbnail—which is the default—is the better choice for longer lists.

A link that starts at the right spot

The classic scenario: someone wants to share the clip at 1:05 in the third video. Two options are all you need.

The timecode accepts seconds (65) or a time format (00:01:05.500). If the requested media is not part of the playlist, the player starts playing the first item instead of remaining blank.

To automate back-and-forth navigation, enable shareParams: the player will then read ?media=...&t=... from the page’s URL and can generate the same link for the current position.

The names of the two URL parameters are configurable, in case “media” and “t” are already in use on your site.

Control the player from your page

generatePlaylistPlayer returns a controller. This means you’re not limited to the buttons provided: a custom table of contents, a keyboard shortcut, or an external chapter list can control playback.

Two callbacks round out the set: onMediaChange(media, index) whenever the video changes—useful for your audience tracking tool—and onPlaylistEnd() when the last track ends, if you want to play something else next. With loop: true, the playlist loops back to the beginning.

Styling the Player

Each generated element has a prefixed class, with “sl-playlist” as the default: sl-playlist-info-title, sl-playlist-item, sl-playlist-button-next… The embedded stylesheet uses only simple class selectors, so your rules will override it without any specificity battles or !important declarations.

The currently playing media item has the is-active class in the list. If you’d prefer to start with a blank page, injectStyles: false disables the default stylesheet; classPrefix renames all classes to align them with your naming convention. The list’s position can be set using listPosition: right, left, bottom, or top.

A time-saving detail

autostart: true instructs the player to start automatically. Browsers, however, block automatic playback with sound: on a page where the visitor hasn’t clicked anything yet, add muted: true to playerParams if you want the player to start immediately. When navigating within the playlist, this isn’t an issue—the user’s click serves as permission, and each subsequent video starts on its own.

Give it a try

Start with the bare minimum, enable the features that matter for your page, and then set up timecode sharing. The demo included with the SDK (demo/playlist-player.html) lets you toggle each option on the fly to find the right configuration before implementing it in your code.

Share this post