-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvideojs-ima.html
147 lines (133 loc) · 5.9 KB
/
videojs-ima.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=3.0, user-scalable=yes">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title> VAST3 VideoJS </title>
<link rel="stylesheet" href="css/video-js.css">
<!-- <link rel="stylesheet" href="videojs-ima/video-js.css"> -->
<!-- <link rel="stylesheet" href="videojs-ima/video-js-add.css"> -->
<link rel="stylesheet" type="text/css" href="css/videojs.ads.css" />
<link rel="stylesheet" type="text/css" href="videojs-ima/videojs.ima.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<script src="js/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/video.js"></script>
<script type="text/javascript" src="js/videojs.watermark.js"></script>
<script type="text/javascript" src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
<script type="text/javascript" src="js/videojs.ads.js"></script>
<script type="text/javascript" src="videojs-ima/videojs.ima.js"></script>
</head>
<body>
<div class="col-xs-12" style="max-width:490px !important; padding-top: 20px; margin:0 auto;">
<div class="videocontent">
<video id="video_media" class="video-js vjs-fluid vjs-big-play-centered" poster='http://cdn.static.tuoitre.vn/i/s639/2016/10/pZePEXSf.jpg'>
<source src="http://cdn.static.tuoitre.vn/2016/10/BnUCSYon.mp4" type='video/mp4'/>
</video>
</div>
</div>
<script>
var options = {
id: 'content_video',
adTagUrl: 'http://adserver.dev/ads.xml',
debug: true,
autoPlayAdBreaks: true
};
var player = videojs("video_media", {
aspectRatio: "16:9",
controls: true,
autoplay: false,
preload: "auto",
fluid: true
}, function() {
this.on("pause", function() {
$("#video_1 .vjs-big-play-button").show();
});
this.on("play", function() {
$("#video_1 .vjs-big-play-button").hide();
});
});
player.ima(options);
player.ima.requestAds();
var startEvent = 'click';
if (navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/Android/i)) {
startEvent = 'touchend';
}
player.one(startEvent, function() {
player.ima.initializeAdDisplayContainer();
player.ima.requestAds();
player.play();
});
player.on('adsready', function() {
console.log("adsready");
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.STARTED, function(adEvent) {
sonuc = adEvent.getAd().isLinear();
console.log("isLinear: " + sonuc);
console.log("ad started");
$('#ima-controls-div').css('display', 'block');
$('#ima-ad-container').css('display', 'block');
if (!sonuc) {
$('#ima-controls-div').css('display', 'none');
setTimeout(function() {
$('#ima-ad-container').css('display', 'none');
}, 15000);
}
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED, function() {
console.log("content resumed");
$('#ima-ad-container').css('display', 'none');
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED, function() {
console.log("content paused");
$('#ima-ad-container').css('display', 'none');
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.COMPLETE, function() {
console.log("ad completed");
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.LINEAR_CHANGED, function() {
console.log("linear changed");
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.LOADED, function() {
console.log("ad loaded");
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.LOG, function(a) {
console.log("logged" + a);
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.SKIPPED, function() {
console.log("ad skipped");
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.USER_CLOSE, function() {
sonuc = adEvent.getAd().isLinear();
console.log("user closed");
if (sonuc) {
$('#ima-ad-container').css('display', 'none');
$('#ima-controls-div').css('display', 'none');
}
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.AD_BREAK_READY, function() {
console.log("ad break ready");
});
player.ima.getAdsManager().addEventListener(google.ima.AdEvent.Type.AD_METADATA, function() {
console.log("ad metadata");
});
});
$("#video_media").bind("contextmenu", function(event) {
if ($(".videojs-rightclick").length) $("div.videojs-rightclick").remove();
event.preventDefault();
$('<div class="videojs-rightclick"><a href="http://vietdien2005.github.io">© Copyright 2016 vietdien2005</a></div>').appendTo("body").css({
top: event.pageY + "px",
left: event.pageX + "px"
});
}).bind("click", function(event) {
$("div.videojs-rightclick").remove();
});
$(document).on("click", function(event) {
$("div.videojs-rightclick").remove();
});
</script>
</body>
</html>