Skip to content

Instantly share code, notes, and snippets.

@dmlap
Last active August 29, 2015 14:16
Show Gist options
  • Save dmlap/19caa5f392f471cc404d to your computer and use it in GitHub Desktop.
Save dmlap/19caa5f392f471cc404d to your computer and use it in GitHub Desktop.
Using TVE with a Brightcove Player.
<!doctype html>
<html>
<head>
<title>TVE Example</title>
</head>
<body>
<!-- Make sure your player doesn't have a video associated with it
and don't use data-video-id to assign one. We'll request a video
from the catalog by hand, detect that it's TVE content, trigger TVE
authentication and then load the video into the player. -->
<video id="tve-player"
data-account="account1234"
data-player="player-id"
class="video-js"
controls>
</video>
<script src="//players.brightcove.net/account1234/player-id_default/index.min.js"></script>
<script>
var player = videojs('tve-player');
player.ready(function() {
player.catalog.getVideo('ref:tve-video', function(error, video) {
if (error) {
// showErrorMessage() would be defined by you somewhere else
// in the page
return showErrorMessage(error);
}
// You can tell whether a video is TVE protected by checking to
// see if the video sources contain URLs. If they don't, you need
// to authenticate your viewer and re-request the video with their
// TVE credentials.
if (video.sources && video.sources[0].src) {
// This is not a TVE video so it can be played back immediately
return player.catalog.load(video);
}
// From here on, we're definitely dealing with a TVE video.
// You need to provide an implementation for authenticateWithTVE()
// to get a TVE token. See the documentation from your TVE provider
// for details on how to do that.
autenticateWithTVE(function(error, tveToken) {
if (error) {
return showErorMessage(error);
}
// Now that we have the token, we can re-request the video and get playable URLs.
player.catalog.tveToken = tveToken;
player.catalog.getVideo('ref:tve-video', function(error, video) {
if (error) {
return showErrorMessage(error);
}
player.catalog.load(video);
});
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment