Developer Guide Javascript API Reference Developer Tools Release Notes

Autostart Only Once

A demo setup that autostarts the video - but only for the first time a user visits the page.

github
const storageKey = 'jwplayer.page-reloaded';

let shouldAutostart = true;
const wasReloaded = JSON.parse(localStorage.getItem(storageKey));
if (wasReloaded) {
  shouldAutostart = false;
}

jwplayer('player').setup({
  playlist: 'https://cdn.jwplayer.com/v2/media/tkM1zvBq',
  // Do not autostart if the page was reloaded.
  autostart: shouldAutostart
});

localStorage.setItem(storageKey, true);

const refreshBtn = document.querySelector('.refresh');
refreshBtn.addEventListener('click', () => window.location.reload());

const clearStorageBtn = document.querySelector('.clear-storage');
clearStorageBtn.addEventListener('click', () => {
  localStorage.removeItem(storageKey);
  refreshBtn.click();
});
This player implementation is a Proof of Concept only provided to show the possibilities of the JW Player and Platform and should not be taken as an offer to create, edit or maintain custom integration or development.