brightcove / player-loader

An asynchronous script loader and embed generator for the Brightcove Player.
Other
28 stars 15 forks source link

Want to load the player with a new videoID #75

Closed lschneiderman closed 3 years ago

lschneiderman commented 3 years ago

How would I keep the player but load a new video into it?

brightcovePlayerLoader({ refNode: document.querySelector('#mainvid'), accountId: myAccountNum, playerId: '947WeZ6d', videoId: myVidID }) .then(function(success) { myPlayer = success.ref; myPlayer.on('loadedmetadata',function(){ $('.vid-thumbnail').on('click', function() { var vidChunk = $(this).parent(); var thisID = vidChunk.attr("id"); thisID = thisID.replace("vidchunk",""); //gives me a videoID $(this).videoId = thisID; //error is: Uncaught TypeError: $(...).videoId is not a function }); ); }) .catch(function(error) { console.log('error', error); });

TheCeloReis commented 3 years ago

brightcovePlayerLoader({
  refNode: document.querySelector("#mainvid"),
  accountId: myAccountNum,
  playerId: "947WeZ6d",
  videoId: myVidID,
})
  .then(function (success) {
    myPlayer = success.ref
    myPlayer.on("loadedmetadata", function () {
      $(".vid-thumbnail").on("click", function () {
        var vidChunk = $(this).parent()
        var thisID = vidChunk.attr("id")
        thisID = thisID.replace("vidchunk", "") //gives me a videoID
        $(this).videoId = thisID //error is: Uncaught TypeError: $(...).videoId is not a function
      })
    })
  })
  .catch(function (error) {
    console.log("error", error)
  })
gkatsev commented 3 years ago

You can use the catalog API on the player to load the new video ID

brightcovePlayerLoader({
  refNode: document.querySelector("#mainvid"),
  accountId: myAccountNum,
  playerId: "947WeZ6d",
  videoId: myVidID,
})
  .then(function (success) {
    myPlayer = success.ref
    myPlayer.on("loadedmetadata", function () {
      $(".vid-thumbnail").on("click", function () {
        var vidChunk = $(this).parent()
        var thisID = vidChunk.attr("id")
        thisID = thisID.replace("vidchunk", "") //gives me a videoID

        // load a new video ID
        myPlayer.catalog.getVideo(thisID, funciton(err, video) {
          if (err) {
            console.log('couldn't get video');
            return;
          }

          myPlayer.catalog.load(video);
        });
      })
    })
  })
  .catch(function (error) {
    console.log("error", error)
  })