强制用户观看整个视频

时间:2015-03-16 17:04:29

标签: video

我搜索如何强制用户观看整个视频,并在每个视频的末尾有一个小按钮,这会触发一个javascript函数 任何类型的视频或阅读器。 感谢

1 个答案:

答案 0 :(得分:3)

我想实现一个类似的概念,我尝试寻求帮助,但没有得到任何,所以我使用jquery DOM操作实现它。以下是代码:

<html>
<head>
<script src="http://www.youtube.com/player_api"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<div id="youtubevideo"></div>
<script>

// create player
var youtubevideo;
function onYouTubePlayerAPIReady() {
    youtubevideo = new YT.Player('youtubevideo', {
      height: '390',
      width: '640',
      videoId: 'hS5CfP8n_js',


//Here the video autoplays, the player hide controls and disable keyboard to prevent users from running past the video. NB: Autoplay only works on PCs. iOS 8 also forces Native controls.

      playerVars:{'rel':0,'showinfo':0,'autoplay':1,'controls':0,'disablekb':1,'modestbranding':1},
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
}


function onPlayerReady(event) {
    event.target.playVideo();
}

//This tells the youtube player to trigger the hello() function when done
function onPlayerStateChange(event) {        
    if(event.data === 0) {            
        hello();
    }
}

//THe hello function uses ajax to bring up html after the video ends. It is achieved using jquery DOM manupulation

function hello(){var i='HTML GOES HERE';$("body").html(i)}
</script>
</body
<html>

您可以在此处查看:http://jsfiddle.net/Ljbwbjsf/1/

你可以在很多玩家中实现这一点,我只是以youtube为例。