-
Notifications
You must be signed in to change notification settings - Fork 2
/
index-API.html
executable file
·307 lines (278 loc) · 11.6 KB
/
index-API.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Kaltura Interactive Player</title>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"
></script>
</head>
<body>
<!-- relevant for development only! -->
<!-- 0.36.6 -->
<!-- <script src="https://qa-apache-php7.dev.kaltura.com/p/6222/embedPlaykitJs/uiconf_id/15219305"></script> -->
<!-- THIS UICONF HAS GA -->
<!-- 0.37.3 -->
<script src="https://qa-apache-php7.dev.kaltura.com/p/6222/embedPlaykitJs/uiconf_id/15220027"></script>
<!-- 0.39.0 -->
<!-- <script src="http://cdnapisec.kaltura.com/p/27017/embedPlaykitJs/uiconf_id/43642002"></script> -->
<script src="dist/path-kaltura-player.js" type="text/javascript"></script>
<script src="http://localhost:35729/livereload.js"></script>
<!-- end of relevant for development only! -->
<!-- 350 x 197 / 260 x 146 / 500 x 281 / 150 x 84 ⬇ ︎-->
<style>
#player {
width: 500px;
height: 281px;
}
</style>
<h3>test.template.html</h3>
<h4 id="projDetails"></h4>
<div id="player"></div>
<div
id="logDiv"
style="width: 450px;height: 100%;position: absolute;left:650px;top:0"
></div>
<script>
var optionalPlaylists = [
{
name: "prefetch API",
selected: true, ///////////////////////
id: "0_vd5gg2z6"
}
];
var selectedItem;
for (var j = 0; j < optionalPlaylists.length; j++) {
if (optionalPlaylists[j].selected) {
selectedItem = optionalPlaylists[j];
}
}
var env = {};
if (selectedItem.isQA) {
env = {
serviceUrl: "//qa-apache-php7.dev.kaltura.com/api_v3",
cdnUrl: "//qa-apache-php7.dev.kaltura.com"
};
}
var pid = 27017; // default
document.getElementById("projDetails").textContent =
selectedItem.name + " - " + selectedItem.id;
var config = {
targetId: "player",
playback: {
// autoplay: false,
preload: "auto"
},
provider: {
// ks : "djJ8NTgwOXw3pr1EYEVjHHuRis2NzxYDzhyn4RnPuMmUhD4GZGmLDEf4oKfJe8xRiSx77VvInhSq8vrHNKc1cMlIitvfyRMpGBKUXNBamu4Rr2-WBGranp5gldiNWQh6l6cKXu0MP3bgj_1fbNVuZSv1t5vEK1dbJdgdSkDmiuTVc9Xhb2folNWucEQYQDSd72z8eIubs10EGzZU1HC28Yl7yofo05OpEXyfpgo_NdFA5D08hTaPmovwUakED2z7gD5AiS6H_gW0wYu95olXSNIPN0em4M4p",
partnerId: pid,
uiconfId: "15219991"
},
rapt: {
initialBitrate: 75e4,
debug: true,
bufferNextNodes: true,
bufferTime: 6,
showScrubber: true,
showTimers: true,
showSettings: true
}
};
var kip = PathKalturaPlayer.setup(config);
var allEvents = [
"hotspot:click",
"node:enter",
"node:ended",
"node:exit",
"project:load",
"project:ready",
"buffer:prebuffer",
"buffer:bufferend",
"buffer:bufferstart",
"buffer:allbuffered",
"project:start",
];
for (var i = 0; i < allEvents.length; i++) {
kip.addListener(allEvents[i], function (event) {
handleInteractiveEvent(event);
});
}
kip.loadMedia({playlistId: "0_vd5gg2z6"});
// logger - debug mode !
function handleInteractiveEvent(event) {
var oneLine = document.createElement("div");
// mark buffering event in green
var printStr = event.type;
var payload = event.payload;
oneLine.style.cssText = "color: blue";
switch (event.type) {
case "buffer:prebuffer":
// payload is an array of the next items - first element is the item we are switching to, all other are the
// next nodes that we will load - by natural order (timeline appearance first, defaultPath later)
// hard coded - if we are about to load street-food-main - we will push 3 other nodes before the default path
//
if (payload.length) {
switch (payload[0].name) {
// On the 'start' node we want to add dynamically 'Street food' to pre-buffer list. We will push it to the top
// of the list so it pre-buffers before the 'food' (chocolate video) entry.
case "Start":
// find the node of video we want to add
var streetFoodMainNode = kip.data.nodes.find(node => node.name === "street food main");
// insert it to the 2nd position of the array
payload.splice(1, 0, streetFoodMainNode);
printStr +=
'<span style="color: #648b24"> [' +
'Start - add Street-food ' +
"]</span>";
break;
case "street food main":
// Example of finding by node name
var streetFood1 = kip.data.nodes.find(node => node.name === "street food 1");
// Example of finding by node id
var streetFood2 = kip.data.nodes.find(node => node.id === "8a8807ee-acdd-42ae-8e33-b85643b22ca2");
// Example of finding by node customData
var streetFood3 = kip.data.nodes.find(node => node.customData === "food3");
payload.push(streetFood1, streetFood2, streetFood3);
printStr +=
'<span style="color: #648b24"> [' +
'API adding food 1-3' +
"]</span>";
break;
case "food main":
// Example of finding by node name
var grapesNode = kip.data.nodes.find(node => node.name === "grapes");
// Example of finding by node id
var coffeeNode = kip.data.nodes.find(node => node.id === "0f92c236-72a8-4d53-844f-0bf612b1b817");
// Example of finding by node customData
var wineNode = kip.data.nodes.find(node => node.customData === "wine");
payload.push(grapesNode, coffeeNode, wineNode);
printStr +=
'<span style="color: #648b24"> [' +
'ChocolatChocolatChocolat' +
"]</span>";
break;
case "food default path":
var food4 = kip.data.nodes.find(node => node.name === "street food 4");
// insert it to the 2nd position of the array
payload.push(food4);
printStr +=
'<span style="color: #648b24"> [' +
'Start - add Street food 4' +
"]</span>";
break;
}
// alter payload object - add more items. This must be a synchronous code
// we can access the nodes from kip.data.nodes and filter by name, id, custom-data or entryId
}
break;
case "hotspot:click":
printStr +=
'<span style="color: #648b24"> [' +
payload.hotspot.name +
"]</span>";
// If there is a custom-data value it will be in payload.hotspot.customData
// sample of detecting the hotspot by custom-data:
if (payload.hotspot.customData && (
payload.hotspot.customData === "street-food" ||
payload.hotspot.customData === "food1" ||
payload.hotspot.customData === "food2" ||
payload.hotspot.customData === "food3" ||
payload.hotspot.customData === "food4"
)) {
switch (payload.hotspot.customData) {
case "street-food":
// jump by node name
kip.jump({name: 'street food main'});
break;
case "food1":
// jump by node id
kip.jump({id: '076fdbc8-61cd-462f-934c-ac04ba9de28c'});
break;
case "food2":
// jump by node name
kip.jump({name: 'food2'});
break;
case "food3":
// jump by node id
kip.jump({id: '1ca66c6a-51df-4a73-ba64-cd67210d1148'});
break;
case "food4":
// jump by node id
kip.jump({id: 'ccee5b3a-3436-4cbd-ad88-e68d86ca2431'});
break;
}
}
// sample of detecting the hotspot by node name:
if (
payload.hotspot.name === "Wine" ||
payload.hotspot.name === "Grapes" ||
payload.hotspot.name === "Coffee"
) {
switch (payload.hotspot.name) {
case "Wine":
// jump by node id
kip.jump({id: 'b7258214-659a-41c6-bc28-e3867d52a0fb'});
break;
case "Grapes":
// jump by node name
kip.jump({name: 'grapes'});
break;
case "Coffee":
// jump by node id
kip.jump({name: 'coffee'});
break;
}
}
break;
case "node:enter":
case "node:ended":
case "node:exit":
printStr +=
'<span style="color: #24468b"> [' +
payload.node.name +
"]</span>";
break;
case "player:progress":
printStr +=
'<span style="color: #8b2136"> [' + payload.progress + "]</span>";
break;
case "browser:open":
printStr +=
'<span style="color: #648b24"> [' + payload.href + "]</span>";
break;
default:
if (!isEmpty(payload)) {
printStr +=
'<span style="color: #9f4e8e"> [' +
payload.toString() +
"]</span>";
}
// this is a Rapt event
}
oneLine.innerHTML = printStr;
document.getElementById("logDiv").appendChild(oneLine);
}
function seekKip(n) {
kip.seek(n);
}
// helpers
function isEmpty(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) return false;
}
return true;
}
</script>
<br/>
<div>
<button onclick="seekKip(kip.duration-3)" style="background: #f4cd98">
Seek to -3sec
</button>
<button onclick="seekKip(kip.duration-7)" style="background: #f4Fd98">
Seek to -7sec
</button>
</div>
</body>
</html>