How to setup a playlist in jwplayer?

49 views Asked by At

I'm trying to setup jwplayer with DRM. I want to use playlist[].sources[] for this.

My code looks like this:

jwplayer.setup({
  playlist: [{
    sources: [
      { file: 'myfile1...' },
      { file: 'myfile2...' },
    ]
  }]
});

But I have this error: Cannot add property default, object is not extensible.
If I remove sources and just go with a file, I have no error:

jwplayer.setup({
  playlist: [{
    file: 'myfile1...',
  }]
});

But then, I can't setup multiple version of my file to handle DRM.
What can I do?

1

There are 1 answers

0
webdif On

I finally found the issue. The code is actually somthing like this:

const sources = [...];

// ...

jwplayer.setup({
  playlist: [{
    sources,
  }]
});

Making a copy resolve the bug:

const sources = [...];

// ...

jwplayer.setup({
  playlist: [{
    sources: sources.map(source => ({ ...source })),
  }]
});

jwplayer will mutate object to add a default prop, so if your sources are memoized or an immutable object in some way, it will break.