我有一个有两页的小应用程序。登录页面之后,第一页是一个目录,其中包含视频列表,用户可以从中选择自己选择的YouTube视频。当用户从侧边栏菜单中选择视频时,他们将被带到视频播放的页面,我将其包含在下面的代码中。这个应用程序使用xAPI Youtube视频跟踪 - 在Github上的ADL,它基本上做广告发送任何数量的语句,如启动,暂停,恢复和完成。但问题是,它并不总是发送"启动"声明。例如,如果我预览视频并确定它是我想要的视频,我将对其进行编码。然后,如果我以John Doe身份登录并播放它,则第一个语句是" resume。&# 34;这是因为我自己预览了视频而youtube以某种方式记得这个吗?我的代码下面是否有引起这种情况的原因?如果我在没有预览的情况下对youtube视频进行编码,它似乎会按照人们的预期发送一个启动语句。谢谢。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Play Video</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/simple-sidebar.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/myStyles.css" rel="stylesheet">
<!-- jQuery -->
<script src="js/jquery.js"></script>
<script src="js/init.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!--optional logo-->
<div class="navbar-header">
<a href="#" class="navbar-brand"><img src="images/justSyniverse.png" width="169" height="43"></a>
</div>
</div>
</nav>
<div id="wrapper">
<div id="sidebar-wrapper" class="list-group">
<a href="tableOfContents.html" class="list-group-item active">
<i class="icon-dashboard"></i> Table of Contents
</a>
<!--************** Ansible *************-->
<!--***** Parent button ******-->
<a href="#ansible" class="list-group-item" data-parent="#sidebar-wrapper">
<i class="icon-group"></i> Ansible
<span class="badge bg_danger"></span>
</a>
<div id="ansible" class="list-group subitem collapse">
<a href="playVideoPage.html?Title=What Is Ansible%3F&emCode=xMHVvHZ-Zn4" class="list-group-item">
<i class="icon-caret-right"></i> What is Ansible?
<span class="badge bg_danger"></span>
</a>
<a href="playVideoPage.html?Title=Getting Started&emCode=In9XI-3ByQ8" class="list-group-item">
<i class="icon-caret-right"></i> Getting Started
</a>
<a href="playVideoPage.html?Title=Concepts Explained&emCode=2jXHxkLBOHg" class="list-group-item">
<i class="icon-caret-right"></i> Concepts Explained
</a>
</div>
<!--************** end Ansible ************-->
<!--************** Chef *************-->
<!--***** Parent button ******-->
<a href="#chef" class="list-group-item" data-parent="#sidebar-wrapper">
<i class="icon-group"></i> Chef
<span class="badge bg_danger"></span>
</a>
<div id="chef" class="list-group subitem collapse">
<a href="playVideoPage.html?Title=Overview of Chef&emCode=yh9osPQA_-k" class="list-group-item">
<i class="icon-caret-right"></i> Overview of Chef
<span class="badge bg_danger"></span>
</a>
<a href="playVideoPage.html?Title=Install Chef&emCode=r3mN2M9n51Y" class="list-group-item">
<i class="icon-caret-right"></i> Install Chef
</a>
<a href="playVideoPage.html?Title=Setup a node %26 write to a cookbook&emCode=71Cq4bCxgDk" class="list-group-item">
<i class="icon-caret-right"></i> Setup a node & write to a cookbook
</a>
<a href="playVideoPage.html?Title=Client Run %26 expanding the cookbook&emCode=H3Ggublb378" class="list-group-item">
<i class="icon-caret-right"></i> Client Run & expanding the cookbook
</a>
</div>
<!--************** end Chef ************-->
<!--************** Docker ************-->
<!--***** Parent button ******-->
<a href="#docker" class="list-group-item" data-parent="#sidebar-wrapper">
<i class="icon-group"></i> Docker
<span class="badge bg_danger"></span>
</a>
<div id="docker" class="list-group subitem collapse">
<a href="playVideoPage.html?Title=What Is Docker%3F&emCode=t9YuqwGYUUg" class="list-group-item">
<i class="icon-caret-right"></i> What is Docker?
<span class="badge bg_danger"></span>
</a>
<a href="playVideoPage.html?Title=Run a %27hello world%27 container&emCode=JBODRMslzAU" class="list-group-item">
<i class="icon-caret-right"></i> Run a 'Hello World' container
<span class="badge bg_danger"></span>
</a>
</div>
<!--************** end Docker ************-->
<!--Logout-->
<a href="#" id="logout" class="list-group-item">
<i class="icon-caret-right"></i> Logout
</a>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 id="myMainTitle">Video Plays here</h1>
<p>Lorem ipsum... </p>
<!--<p>Make sure to keep all page content within the <code>#page-content-wrapper</code>.</p>-->
<!--<a href="#menu-toggle" class="btn btn-default" id="menu-toggle">Toggle Menu</a>-->
<div id="player"></div>
<script type="text/javascript" src="lib/xapiwrapper.min.js"></script>
<script type="text/javascript" src="src/xapi-youtube-statements.js"></script>
<script type="text/javascript" src="src/videoprofile.js"></script>
<script>
<!--This pulls the variables from the url query string-->
var urlParams;
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
<!--This creates a var from the youtube embed code-->
var video = urlParams["emCode"];
<!--This creates a variable of the actual youtube title-->
var videoTitle = urlParams["Title"];
$("#myMainTitle").text(videoTitle);
<!--We have to pull the global variables from localStorage-->
var name = localStorage.getItem('name');
var email = localStorage.getItem('email');
//var mEmail = email;
// var personName = name;
// "global" variables read by ADL.XAPIYoutubeStatements
ADL.XAPIYoutubeStatements.changeConfig({
"actor": {"mbox":"mailto:" + email, "name":name},
"videoActivity": {"id":"https://www.youtube.com/watch?v=" + video, "definition":{"name": {"en-US":videoTitle}} }
});
function initYT() {
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: video,
playerVars: { 'autoplay': 0 },
events: {
'onReady': ADL.XAPIYoutubeStatements.onPlayerReady,
'onStateChange': ADL.XAPIYoutubeStatements.onStateChange
}
});
}
initYT();
// Auth for the LRS
var conf = {
"endpoint" : "https://lrs.adlnet.gov/xapi/",
"auth" : "Basic " + toBase64("xapi-tools:xapi-tools"),
};
ADL.XAPIWrapper.changeConfig(conf);
/*
* Custom Callbacks
*/
ADL.XAPIYoutubeStatements.onPlayerReadyCallback = function(stmt) {
console.log("on ready callback");
}
// Dispatch Youtube statements with XAPIWrapper
ADL.XAPIYoutubeStatements.onStateChangeCallback = function(event, stmt) {
console.log(stmt);
if (stmt) {
stmt['timestamp'] = (new Date()).toISOString();
ADL.XAPIWrapper.sendStatement(stmt, function(){});
} else {
console.warn("no statement found in callback for event: " + event);
}
}
</script>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<script src="js/init.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Menu Toggle Script -->
<script>
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
</script>
</body>
</html>