-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvplayer.js
75 lines (73 loc) · 2.64 KB
/
vplayer.js
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
$( document ).ready(function() {
var URL = window.URL || window.webkitURL;
var displayMsg = function (msg, className){
$('#message')[0].innerHTML = '<p class="'+className+'">' + msg + '</p>';;
};
// Check if blob urls are supported
if (!URL) {
var notSupportedMsg = 'Your browser is not <a href="http://caniuse.com/bloburls">supported</a>!';
displayMsg(notSupportedMsg, 'error');
return;
}
// Load Video (with subtitles)
$('#vidForm').submit(function(event) {
event.preventDefault();
var vInput = $('#vInput')[0];
var sInput = $('#sInput')[0];
// Check if video file has been selected
if (vInput.files && vInput.files.length < 1) {
displayMsg('Please select an input video file', 'error');
return;
}
// Get video file params
var vFile = vInput.files[0];
var vType = vFile.type;
var vUrl = URL.createObjectURL(vFile);
// Get subtitle params
var sFile = "", sType = "", sUrl = "";
if (sInput.files && sInput.files.length > 0) {
sFile = sInput.files[0];
sType = sFile.type;
sUrl = URL.createObjectURL(sFile);
// Append to video element
var trackElem = '<track kind="captions" src="' + sUrl + '" scrlang="en" label="English" default>';
$('#vidPlayer').append(trackElem);
}
// Try playing the video
try{
_V_("vidPlayer").ready(function(){
this.src({ 'type' : vType,
'src' : vUrl
});
this.play();
if (sUrl) {
// Show subtitle class
$('#sAdjust').removeClass('hidden');
// Pin subtitle to bottom
$('.vjs-text-track-display').css('bottom', '1em');
}
});
displayMsg("Video loaded successfully, now you can full screen it and Chromecast it !!!", 'info');
} catch(ex) {
console.log(ex);
}
});
// increase subtitles font size
$('#sIncrease').click(function(event) {
var track = $('.vjs-text-track-display');
var currSize = parseInt(track.css('font-size'), 10);
var newSize = currSize + 5;
track.css('font-size', newSize);
// Pin subtitle to bottom
track.css('bottom', '1em');
});
// decrease subtitles font size
$('#sDecrease').click(function(event) {
var track = $('.vjs-text-track-display');
var currSize = parseInt(track.css('font-size'), 10);
var newSize = currSize - 5;
track.css('font-size', newSize);
// Pin subtitle to bottom
track.css('bottom', '1em');
});
});