-
Notifications
You must be signed in to change notification settings - Fork 4
/
video.htm
608 lines (572 loc) · 28.3 KB
/
video.htm
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>SCALE Video</title>
<link REL="SHORTCUT ICON" HREF="img/favicon.ico">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="lib/jquery.ui.touch-punch.min.js"></script>
<style>
body { font-family:Verdana,Geneva,sans-serif; font-size:13px;padding:0px;margin:0px }
.vp-notes { cursor: pointer; color:#000; float: right;
text-align: center; border-radius: 16px; user-select: none; display:none; margin-left:6px; margin-top:1px;
font-size: 10px; background-color:#999; padding: 0 8px 2px 8px; color: #fff;
}
</style>
</head>
<body>
<div id="showDiv">
<div id="playerDiv" style="width:100%;height:100%;display:none;overflow:hidden; user-select: none"></div>
<div id="slideDiv" style="position:absolute;overflow:hidden;user-select:none"></div>
</div>
<div id="playerSiz" style="position:absolute;width:8px;cursor:col-resize;user-select:none" title="Resize player">
<div id="playerSiz1" style="position:absolute;width:40px;height:100%;left:-16px;user-select:none"></div>
</div>
<script>
//youtu.be/2doZROwdte4
//www.kaltura.com/p/2003471/sp/0/playManifest/entryId/1_c7z7zuiv/format/url/flavorParamId/2003471.mp4
//vimeo.com/274326838
//localhost/video.htm?src=IRVdiHu1VCc\|slides=https://docs.google.com/presentation/d/e/2PACX-1vQMmAXYMlLmBVH3n9hx4_U0OPYSdJwfR-JrI87p5D0ZldfWC9Y0Yxemkh4tYnuh2igiC03gNGHDjGnS/embed|trigger=5-2+10-3+15-2+20-1
var playerSource="";
var playerAuto="false";
var playerNext="false";
var playerStart=0;
var playerEnd=0;
var playerVolume=50;
var playerSpeed=1;
var playerAspect=.5625;
var playerControls="true";
var player=null; // Holds player object
var playerNow=0; // Current time in secs
var playerTime=null; // Timer
var playerMode="empty"; // State of player
var playerCurTime=0; // Current time
var playerTRT=0; // Total running time
var playerHgt,playerWid; // Source height/width
var isMobile=false; // Flag for mobile devices
var playerTime=null; // Timer
var triggers=[]; // Time triggers to do something
var slideSource=""; // Id of slide presentation
var playerSlideRatio=1; // Player slider ratio
var paneAnimationTimer=null; // Animating panes
var showNotes=false; // Show notes button?
var showTrans=0; // Show transcript button?
var showTOC=0; // Show TOC button?
var v=window.location.search.substring(1).split("|"); // Get query string
for (i=0;i<v.length;++i) { // For each param
if (v[i].match(/src=/i)) playerSource=GetDirectLink(v[i].substr(4)); // Set src
if (v[i].match(/start=/i)) playerStart=v[i].substr(6)-0; // Set start
if (v[i].match(/end=/i)) playerEnd=v[i].substr(4); // Set end
if (v[i].match(/auto=/i)) playerAuto=v[i].substr(5); // Set auto
if (v[i].match(/next=/i)) playerNext=v[i].substr(5); // Set next
if (v[i].match(/trigger=/i)) triggers=v[i].substr(8).split("+"); // Set triggers
if (v[i].match(/slides=/i)) slideSource=v[i].substr(7); // Set slides source
if (v[i].match(/split=/i)) playerSlideRatio=v[i].substr(6)/100; // Set start
if (v[i].match(/notes=/i)) showNotes=true; // Show notes button
if (v[i].match(/trans=/i)) showTrans=v[i].substr(6); // Show transcripts button
if (v[i].match(/toc=/i)) showTOC=v[i].substr(4); // Show TOC button
}
for (var i=0;i<triggers.length;++i) // For each trigger
triggers[i]=triggers[i].split("-"); // Split time-action
$(document).ready(function() { // When loaded
if (window.addEventListener) // If supported this way
window.addEventListener("message",shivaEventHandler,false); // Add event handler
else // Use other method
window.attachEvent("message",shivaEventHandler); // Add handler
isMobile=navigator.userAgent.match(/(ipad|iphone|ipod|android)/i) ? true : false; // Set mobile flag
$(window).resize(ResizePanes); // On window resizing
playerTimer=setInterval(OnPlayerTimer,200); // Set timer ~5ps
if (slideSource) { // If showing slides
if (playerSlideRatio == 1) playerSlideRatio=.5; // Assume 50% if no split set
$("#slideDiv").html("<iframe id='slideDivIF' frameborder='0' width='100%' src='"+slideSource+"'></iframe>"); // Load in iframe
}
else{ // No slides
$("#slideDiv").remove(); // Remove divs
$("#playerSiz").remove();
}
Init(); // Init player
$("body").append("<span id='notesBut' onclick='SendScaleMessage(\"notes\")' class='vp-notes'>Take notes</span>"); // Add notes button
$("body").append("<div id='transBut' onclick='SendScaleMessage(\"trans\",\""+showTrans+"\")' class='vp-notes'>Transcript</div>"); // Add transcript button
$("body").append("<div id='tocBut' onclick='SendScaleMessage(\"toc\",\""+showTOC+"\")' class='vp-notes'>Contents</div>"); // Add contents button
});
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PANES
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$("#playerSiz").draggable({ // DRAG PLAYER WIDTH HANDLER
cursorAt:{left:16}, iframeFix:true, // Cursor offset
cursor: "col-resize", axis:"x", // X-only
start: function(event, ui) { // On drag start
$("#playerSiz1").css({ width:"500px", left:(offx-500)+"px" }); // Widen hiding div
},
drag: function(event, ui) { // On drag
var wid=$("body").width(); // Get screen size
playerSlideRatio=Math.max(0,Math.min(1,(event.clientX-offx-8)/(wid+16))); // Set ratio between windows
if (Math.abs(playerSlideRatio-.5) < .01) // If close to center
playerSlideRatio=.5; // Snap it there
ResizePanes(); // Resize panes
},
stop: function(event, ui) { // On drag end
$("#playerSiz1").css({ width:"40px", left:(offx-16)+"px" }); // Contract hiding div
ResizePanes(); // Resize panes
}
});
$("#playerSiz").hover( // Player width
function(){ $(this).css("background-color","#acc3db")}, // Highlight
function(){ $(this).css("background-color","transparent") // Hide
});
function ResizePanes() // RESIZE PANES
{
var wid=$("body").width(); // Cap at screen size
var w=(wid*playerSlideRatio)+4; // Player width
var w2=wid-w-8; // Slide width
if (w <= 0) w=0,w2=wid; // Full slide
else if (w2 <= 0) w2=0,w=wid; // Full video
var h=Math.max(((wid-4)*playerAspect)-(w*playerAspect),w*playerAspect); // Player height
$("#playerDiv").css({ width:w+"px",top:0 }); // Set player pos
offx=$("#playerDiv").offset().left; // Offset X from base
$("#slideDiv").css({ left:(wid+offx-w2)+"px",width:w2+"px",top:0,height:h+"px"}); // Set slider pos/size
$("#playerSiz").css({ left:(w+offx)+"px",height:h+"px",top:0}); // Set sizer pos
RunPlayer("resize"); // Resize player
$("#slideDivIF").height($("#slideDiv").height()-2); // Set iframe height, if any
}
function AnimatePanes(end, dur,) // ANIMATE CHANGE OF PANE RATIO
{
var start=playerSlideRatio; // Get current player ratio
var dif=Math.abs(end-start); // Difference
if ((dif < .05) || (paneAnimationTimer)) { // If close enough or animating alredy
clearInterval(paneAnimationTimer); // Kill timer
paneAnimationTimer=null; // Clear timer var
playerSlideRatio=end; // Set player ratio
if (dif) // If not there yet
ResizePanes(); // Resize
return; // Quit
}
clearInterval(paneAnimationTimer); // Kill timer
paneAnimationTimer=null; // Clear timer var
var startTime=new Date().getTime(); // Set start
if (dur == undefined) // If no duration set
dur=.5; // Set default
dur=dur*1000; // Secs to ms
if (playerMode != "play") // If not playing
dur=1; // Go to end quickly
paneAnimationTimer=setInterval(onAnimate,24); // Set timer ~40ps
function onAnimate() {
var now=(new Date().getTime()-startTime)/dur; // Get now
now=1.0-((Math.cos(3.1414*Math.min(now,1))+1)/2.0); // Full cosine curve
var pos=start+(end-start)*now; // Get val
if (now > .99) { // If done
clearInterval(paneAnimationTimer); // Kill timer
pos=end; // Force to end
paneAnimationTimer=null; // Null it out
}
playerSlideRatio=pos; // Set player ratio
ResizePanes(); // Resize
}
}
function GetPlayerTime() // GET TIME FROM PLAYER
{
if (playerType == "youtube") // If YouTube
playerCurTime=player.getCurrentTime(); // Get curtime
else if (playerType == "html5") // If HTML5
playerCurTime=player.currentTime; // Get cur time
return playerCurTime; // Return time
}
function OnPlayerTimer() // TIMER HANHDLER
{
if (isMobile && (playerType == "html5")) { // IOS HTML5
if ($("#vplayer")[0].readyState == 1) $("#vplayer")[0].canplay(); // Init by hand
}
if ((!player) || (playerMode != "play")) // Not playing
return; // Quit
playerCurTime=GetPlayerTime(); // Get time
if (playerEnd && (playerCurTime >= playerEnd)) { // Past end
RunPlayer("pause"); // Pause
SendScaleMessage("stop",playerEnd); // Send stop
if (playerNext == "true") SendScaleMessage("next"); // Send next if set
}
else if (triggers) { // If triggers defined
var i,t;
for (i=0;i<triggers.length;++i) { // For each trigger
if (Math.abs(playerCurTime-triggers[i][0]) < .15) { // Near trigger point
if (slideSource) { // Has slides
$("#slideDivIF").prop("src",slideSource+"?slide="+triggers[i][1]); // Next slide
}
else{ // Straight video
if (triggers[i][1].charAt(0) == '*') // If not pausing video
SendScaleMessage("trigger",triggers[i][1].substr(1)+"|"+(triggers[i][0]-0+.25)); // Send trigger back
else{
RunPlayer("pause"); // Pause
SendScaleMessage("trigger",triggers[i][1]+"|"+(triggers[i][0]-0+.25)); // Send trigger back
}
triggers[i][0]=-10; // Disable trigger from firing again
}
break; // Quit
}
}
}
// else
// SendScaleMessage("play",now.toFixed(3)); // Send time
}
function Init()
{
ResizePanes(); // Resize panes
if (playerSource.match(/\/\//i)) { // If HTML5
if (player && (playerType == "html5")) { // Player not active loaded
if (player.currentSrc.indexOf(playerSource) == -1) { // Different clip
var base=playerSource.match(/(.*)\.[^.]+$/i)[1]; // Extract base
if (playerSource.match(/\.mp3/i)) // If audio
player.src=base+".mp3"; // MP3 Source
else // VIDEO
player.src=base+".mp4"; // MP4 Source
player.load(); // Load it
}
}
else{
playerType="html5"; // Set type
RunPlayer("init"); // Init player
}
}
else if (!isNaN(playerSource)) { // If Vimeo
playerType="vimeo"; // Set type
RunPlayer("init"); // Init player
}
else{ // If YouTube
playerType="youtube"; // Set type
if (player) { // Player active
if (!player.pauseVideo) { // If not YT player set
if (YT.Player) // If library is loaded
RunPlayer("init"); // Re-init
else{ // Load YT api
var tag=document.createElement('script'); // Create script
tag.src="//www.youtube.com/iframe_api"; // Set api url
var firstScriptTag=document.getElementsByTagName('script')[0]; // Find 1st script
firstScriptTag.parentNode.insertBefore(tag,firstScriptTag); // Load
}
}
else{ // Player is active
if (player.getVideoUrl().indexOf(playerSource) == -1) // Different clip
player.loadVideoById(playerSource); // Reload clip
else
player.seekTo(playerStart); // Seek to start point
if (playerAuto == "true") // If autoplay
player.playVideo(); // Play video
}
}
else{ // API not loaded yet
var tag=document.createElement('script'); // Create script
tag.src="//www.youtube.com/iframe_api"; // Set api url
var firstScriptTag=document.getElementsByTagName('script')[0]; // Find 1st script
firstScriptTag.parentNode.insertBefore(tag,firstScriptTag); // Load
}
}
}
function RunPlayer(what, param, param2) // PLAYER ACTIONS
{
var i,str;
if ((what == "play") || (what == "jump")) { // Play/jump
if ((playerMode == "empty") && isMobile) // Mobiles need user to initiate touch before controlled play
return; // Quit
playerMode="play"; // Set mode
if ((param != undefined) && (param != "")) { // If playing to a time
if ((""+param).match(/:/)) // In tc format
param=TimecodeToSeconds(param); // Convert to secs
playerCurTime=playerNow=param; // Set cur time
}
else if (playerCurTime) // No time set, so resume if not at start
playerCurTime=playerNow=playerCurTime-0+.3 // Set cur time
if (!player) { // If no player yet
return; // Quit
}
if (playerType == "youtube") { // If YouTube
player.seekTo(playerNow,true); // Cue
if (playerMode == "play") player.playVideo(); // Play
else if (playerMode == "pause") player.pauseVideo(); // Pause
}
else if (playerType == "vimeo") { // If Vimeo
player.contentWindow.postMessage("{\"method\":\"seekTo\",\"value\":\""+playerNow+"\"}","*");
if (playerMode == "play") // Play
player.contentWindow.postMessage("{\"method\":\"play\"}","*"); // Send
if (playerMode == "pause") // Pause
player.contentWindow.postMessage("{\"method\":\"pause\"}","*"); // Send
}
else if (playerType == "html5") { // If HTML5
if (player.readyState) // If ready
player.currentTime=playerNow; // Cue
if (playerMode == "play") player.play(); // Play
if (playerMode == "pause") player.pause(); // Pause
}
if (playerMode == "play") playerStarted=playerNow; // Save start point
}
else if ((what == "scrub") || (what == "seek")) { // Scrub
if ((playerMode == "empty") && isMobile) // Mobiles need user to initiate touch before controlled play
return; // Quit
playerCurTime=playerNow=param; // Set now
if (!player) // If no player yet
return; // Quit
if (playerType == "youtube") // If YouTube
player.seekTo(playerNow,true); // Cue
else if (playerType == "vimeo") // If Vimeo
player.contentWindow.postMessage("{\"method\":\"seekTo\",\"value\":\""+playerNow+"\"}","*");
else if (playerType == "html5") // If HTML5
if (player.readyState) // If ready
player.currentTime=playerNow; // Cue
}
else if (what == "pause") { // Pause
playerMode="pause"; // Set mode
if (!player) return; // If no player yet, quit
if (playerType == "youtube") // If YouTube
player.pauseVideo(); // Pause
else if (playerType == "vimeo") // If Vimeo
player.contentWindow.postMessage("{\"method\":\"pause\"}","*"); // Send
else if (playerType == "html5") // If HTML5
player.pause(); // Pause
}
else if (what == "volume") { // Volume
if (!player) return; // If no player yet, quit
if (playerType == "youtube") // If YouTube
player.setVolume(playerVolume); // Set it
else if (playerType == "vimeo") // If Vimeo
player.contentWindow.postMessage("{\"method\":\"setVolume\",\"value\":\""+playerVolume/100+"\"}","*"); // Send
else if (playerType == "html5") // If HTML5
player.volume=playerVolume/100; // Set
}
else if (what == "speed") { // Speed
if (!player) return; // If no player yet, quit
s=Math.max(.25,playerSpeed/50); // Speed set .25 to 2
if (playerType == "youtube") // If initted YouTube
player.setPlaybackRate(s); // Set speed
else if (playerType == "html5") // If HTML5
player.playbackRate=s; // Set speed
}
else if (what == "resize") { // Resize
if (!player) return; // If no player yet, quit
var w=$("#playerDiv").width(); // Get width
if (playerType == "youtube") // If initted YouTube
player.setSize(w,w*playerAspect); // Resize
else if ((playerType == "vimeo") || (playerType == "html5")) { // If Vimeo or HTML5
$("#vplayer").width(w); // Set width
$("#vplayer").height(w*playerAspect); // Set height
}
}
else if (what == "ready") { // When ready
ResizePanes(); // Resize panes
if (playerAuto == "true") // If autoplay
RunPlayer("play",playerStart); // Play
else if (playerStart) // Normal pause start
RunPlayer("seek",playerStart); // Seek
$("#playerDiv").css("display","block"); // Show
if (showNotes) $("#notesBut").show(); // If showing notes, show
if (showTrans) $("#transBut").show(); // If showing transcipt, show
if (showTOC) $("#tocBut").show(); // If showing TOC, show
}
else if (what == "init") { // Init player
if (playerType == "youtube") { // If YouTube
$("#playerDiv").html("<div id='vplayer'></div>"); // Add holder div
var pc=playerControls == "true" ? 1 : 0; // Set player controls?
player=new YT.Player("vplayer", { // Init player
playerVars:{ modestbranding:1, controls:pc, // Settings
disablekb:1, rel:0, showinfo:0, html5:1, autoplay:1 },
videoId: playerSource, // Set source
events:{ // Add event handlers
"onStateChange": function(s) { // Change of state
if (s.data == 1) { // In play
if (playerMode == "empty") { // If first time playing
if (isMobile) // If mobile
player.seekTo(playerStart,true); // Seek to start
else // Desktop
player.pauseVideo(); // Pause
}
playerMode="play"; // Set mode
playerStarted=playerNow; // Save start point
}
else if ((s.data == 2) || (s.data == 0)) // In pause
playerMode="pause"; // Set mode
},
"onReady": function(s) { RunPlayer("ready") } // When ready
}});
}
else if (playerType == "vimeo") { // If Vimeo
str="<iframe id='vplayer' src='//player.vimeo.com/video/"; // Iframe start
str+=playerSource; // Add source
str+="?api=1&player_id=vplayer' width='500' height='281' frameborder='0' allowFullScreen></iframe>";
$("#playerDiv").html(str); // Add vimeo iframe
player=$("#vplayer")[0]; // Point to iframe
}
else if (playerType == "html5") { // If HTML5
$("#playerDiv").html(""); // Add video tag
var base=playerSource.match(/(.*)\.[^.]+$/i)[1]; // Extract base
str="<video id='vplayer' width='100%' height='100%'"; // Video tag
if ((playerControls == "true") || isMobile) // If has controls or mobile
str+= " controls"; // Add native controls to player
str+=">"; // Close tag
if (playerSource.match(/\.mp3/i)) { // If audio
str+="<source src='"+base+".mp3' type='audio/mp3'>"; // MP3 Source
if (!slideSource) playerAspect=60/$("body").width(); // Just show controls, unless showing slides
}
else // VIDEO
str+="<source src='"+base+".mp4' type='video/mp4'>"; // MP4 Source
str+="</video>"
$("#playerDiv").html(str); // Add video tag
var myVid=document.getElementById("vplayer"); // Point at player
player=$("#vplayer")[0]; // Point to player
player.readySent=false; // Ready not sent
if (isMobile) RunPlayer("ready"); // Moble doesn't sent an 'oncanplay' message
myVid.onloadstart=function() { // When loaded
player=$("#vplayer")[0]; // Point to player
player.readySent=false; // Ready not sent
};
myVid.oncanplay=function() { // When ready
if (!playerSource.match(/\.mp3/i)) // If video
playerAspect=player.videoHeight/player.videoWidth; // Set aspect
if (!player.readySent) // Not sent yet
RunPlayer("ready"); // Set up player
player.readySent=true; // Ready sent
};
myVid.onended=function() { // When done
RunPlayer("pause"); // Pause
};
myVid.onplay=function() { // When playing
playerMode="play"; // Set mode
playerStarted=playerNow; // Save start point
};
myVid.onpause=function() { // When paused
playerMode="pause"; // Set mode
};
myVid.addEventListener("canplay",myVid.oncanplay,false); // Add listener for safari
myVid.addEventListener("ended",myVid.onende,false); // Add listener for safari
myVid.addEventListener("play",myVid.onplay,false); // Add listener for safari
myVid.addEventListener("pause",myVid.onpause,false); // Add listener for safari
}
} // End init
} // End closure
function onYouTubeIframeAPIReady() // YOUTUBE PLAYER READY
{
RunPlayer("init"); // Init player
}
function SendScaleMessage(cmd, msg) // SEND MESSAGE TO CONTAINER
{
var str="ScaleVideo="+cmd; // Add header
if (msg) str+="|"+msg; // If more to it, add
if (window.parent) // If has a parent
window.parent.postMessage(str,"*"); // Send message to parent wind
else // Local
window.postMessage(str,"*"); // Send message to wind
}
// //youtu.be/2doZROwdte4
// //www.kaltura.com/p/2003471/sp/0/playManifest/entryId/1_c7z7zuiv/format/url/flavorParamId/2003471.mp4
// //vimeo.com/274326838
// //www.dropbox.com/s/8ng9w16ram24vaa/JapaneseInternment.mp3?dl=0
function GetDirectLink(url) // GET DRECT LINK TO MEDIA
{
if (!url) // If no url
return ""; // Return null
if (url.match(/youtube\.com/i)) // If Youtube link
return url.match(/v=(.+)/i)[1]; // Extract id
if (url.match(/youtu\.be/i)) // If Youtube embed
return url.match(/be\/(.+)/i)[1]; // Extract id
if (url.match(/vimeo\.com\//i)) // A Vimeo url or embed code
return url.match(/vimeo.+\/(\d+)/i)[1]; // Extract id
if (url && url.match(/dropbox\.com/i)) { // A dropbox link
var id=url.match(/\/s\/(.*)\?dl=0/i)[1]; // Extract id
url="https://dl.dropboxusercontent.com/s/"+id; // Construct direct link
}
if (!url.match(/kaltura/)) // Not Kaltura
return url; // Return original
var mid=0; // Media id
var pid=2003471; // Collab partner id
var flv=301971; // Collab video flavor
if (url.match(/<object/i)) { // Object-style embed code
mid=url.match(/kaltura_player_([^"]+)/i)[1]; // Get media id
url="//www.kaltura.com/p/"+pid+"/sp/0/playManifest/entryId/"+mid+"/format/url/video.mp4"
}
else if (url.match(/<iframe/i)) { // Iframe-style embed code
pid=url.match(/partner_id\/(\d+)/i)[1]; // Get partner id
mid=url.match(/entry_id=([^&]+)/)[1]; // Get media id
flv="0_ithj599o"; // MP4 used by mediabase
url="//www.kaltura.com/p/"+pid+"/sp/0/playManifest/entryId/"+mid+"/format/url/video.mp4"
}
else if (url.match(/embed/i)) { // Kaltura link
pid=url.match(/partner_id\/(\d+)/i)[1]; // Get partner id
mid=url.match(/entry_id\/(\w+)/i)[1]; // Get media id
url="//www.kaltura.com/p/"+pid+"/sp/0/playManifest/entryId/"+mid+"/format/url/video.mp4"
}
return url; // Return converted url
}
function shivaEventHandler(e) // ON SHIVA EVENT
{
if (e.origin.match(/vimeo/i)) { // From vimeo
var ev=$.parseJSON(e.data); // Parse json
if (ev.event == "playProgress") { // If playing
playerCurTime=ev.data.seconds; // Set current time
}
else if (ev.event == "play") { // If play
playerMode="play"; // Set mode
playerStarted=playerNow; // Save start point
}
else if ((ev.event == "pause") || (ev.event == "finish")) { // If pause/end
playerMode="pause"; // Set mode
}
else if (ev.method == "getDuration") { // If duration
playerTRT=ev.value; // Get duration
RunPlayer("ready"); // Set up player
}
else if (ev.method == "getVideoHeight") { // If height
playerHgt=ev.value; // Set it
if (playerWid) // If have both parts
playerAspect=playerHgt/playerWid; // Calc asp
}
else if (ev.method == "getVideoWidth") { // If width
playerWid=ev.value; // Set it
if (playerHgt) // If have both parts
playerAspect=playerHgt/playerWid; // Calc asp
}
else if (ev.event == "ready") { // If ready
var f=$("#vplayer"); // Point at iframe
f[0].contentWindow.postMessage("{\"method\":\"addEventListener\",\"value\":\"play\"}","*");
f[0].contentWindow.postMessage("{\"method\":\"addEventListener\",\"value\":\"pause\"}","*");
f[0].contentWindow.postMessage("{\"method\":\"addEventListener\",\"value\":\"playProgress\"}","*");
f[0].contentWindow.postMessage("{\"method\":\"getVideoHeight\"}","*");
f[0].contentWindow.postMessage("{\"method\":\"getVideoWidth\"}","*");
f[0].contentWindow.postMessage("{\"method\":\"getDuration\"}","*");
}
}
else if (e.data.match(/ScaleAct=/)) { // If data
var v=e.data.split("|"); // Split msg into parts
if (v[0] == "ScaleAct=play") // PLAY
RunPlayer("play",v[1] ? v[1] : ""); // Play
else if (v[0] == "ScaleAct=stop") // STOP
RunPlayer("pause"); // Pause
else if (v[0] == "ScaleAct=pause") // PAUSE
RunPlayer("pause"); // Pause
else if (v[0] == "ScaleAct=seek") // SEEK
RunPlayer("seek",v[1]); // Seek
if (v[0] == "ScaleAct=time") { // TIME
GetPlayerTime(); // Get time
SendScaleMessage("time",playerCurTime); // Send back time
}
}
}
function trace(msg, p1, p2, p3, p4) // CONSOLE
{
if (p4 != undefined)
console.log(msg,p1,p2,p3,p4);
else if (p3 != undefined)
console.log(msg,p1,p2,p3);
else if (p2 != undefined)
console.log(msg,p1,p2);
else if (p1 != undefined)
console.log(msg,p1);
else
console.log(msg);
}
function trace2(msg, p1, p2, p3, p4) // IOS CONSOLE
{
msg+=" "+p1 ? p1 : ""; msg+=" "+p2 ? p2 : ""; msg+=" "+p3 ? p3 : "";
$("#contentBodyDiv").append(msg+" ")
console.log(msg)
}
</script>
</body>
</html>