JW player assigns file via variable

playlist: [{

        "sources": [{"type": "video/mp4", "label": "SD", "file": "src.mp4"}] 
}],

how to use js variable to assign src video file as

playlist: [{
"sources": [{"type": "video/mp4", "label": "SD", "file": myvariable    }] 
}],
+4
source share
1 answer

Value fileis a string representing the location of the file. This is usually an absolute URL. For some reason, the demo doesn’t work on SO, but it works like PLUNKER

Note: I used ES6 Template Literal instead of the usual String literal . If you intend to serve IE users, you will need to use String Literal

Demo PLUNKER

Demo STACK (not working), instead of PLUNKER

<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
  <script src="http://p.jwpcdn.com/6/12/jwplayer.js"></script>
</head>

<body>
  <div id="x">...</div>
  <script>
    var file = '023642.mp4';

    var jwp = jwplayer('x');
    jwp.setup({
      playlist: [{
        file: `http://media6000.dropshots.com/photos/1381926/20170326/${file}`
      }],
      width: 320,
      height: 180
    });
  </script>

</body>

</html>
Run codeHide result

✎ OP, Stack . @ @TinyGiant

+3

Source: https://habr.com/ru/post/1684392/


All Articles