Calling Playkit-js player not showing in browser

486 views Asked by At

After spending some 12 hours, I think I have successfully built playkit-js player (https://github.com/kaltura/playkit-js), and obtained a new folder "dist" and new "playkit.js".

There's a folder called "src" which also contains "playkit.js".

Can you kindly help me to call/configure the player and what would be the proper javascript code? As per their docs, I need add the following snippet:

<script type="text/javascript" src="/PATH/TO/FILE/playkit.js"></script>
<div id="player-placeholder" style="height:360px;width:640px">
<script type="text/javascript">
var playerContainer = document.querySelector("#player-placeholder");
var config = {...};
var player = playkit.core.loadPlayer(config);
playerContainer.appendChild(player.getView());
player.play();
</script>

I can't make the player visible in the browser. Where should I add it, and also which "playkit.js" file should I use? I have tried both files but it's not working. Please help.

Here is the html I am using:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style type="text/css">
    #player-placeholder {
      width: 640px;
      height: 360px;
      background-color: black;
    }
  </style>
  <script src="playkit.js" type="text/javascript"></script>
</head>
<body>
<div id="player-placeholder" style="height:360px;width:640px">
<script type="text/javascript">
var playerContainer = document.querySelector("#player-placeholder");
var config = {...};
var player = playkit.core.loadPlayer(config);
playerContainer.appendChild(player.getView());
player.play();
</script>
</body>
</html>
1

There are 1 answers

2
Itay Kinnrot On BEST ANSWER

The play from API sometimes not working due to browser limitations (cant auto play with sound) if you'll add a button it will work. check out this example:

<script src="https://github.com/kaltura/playkit-js/releases/download/v0.59.9/playkit.js"></script>

<div id="player-placeholder" style="height:360px;width:640px">
  <input type="button" onclick="play()" value="Play"/>
  <script type="text/javascript">
var playerContainer = document.querySelector("#player-placeholder");
var config = {
  sources:{
    progressive:[{
      mimetype:"video/mp4",
      url:"https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4"
    }]
  }
}
var player = playkit.core.loadPlayer(config);
playerContainer.appendChild(player.getView());
function play(){
  player.play();
}
</script>

https://codepen.io/itaykinnrot/pen/LYVPGEx