-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
163 lines (163 loc) · 7.63 KB
/
index.html
File metadata and controls
163 lines (163 loc) · 7.63 KB
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
<html>
<head>
<title>HTML5 Video</title>
</head>
<body>
<h1>HTML5 Video</h1>
<div id="video-wrapper">
<video width="960" height="540" controls="controls" id="video">
<source src="assets/3930_2_A-BRITISH-SUMMER.webmhd.webm" type='video/webm; codecs="vp8, vorbis"' />
<source src="assets/3930_2_A-BRITISH-SUMMER.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
</video>
<div id="content"></div>
</div>
<p>References</p>
<ul>
<li><a href="http://www.w3schools.com/tags/ref_av_dom.asp" target="_blank">W3C Schools</a></li>
<li><a href="http://www.html5rocks.com/en/tutorials/video/basics/" target="_blank">HTML5 Rocks</a></li>
<li><a href="http://www.mirovideoconverter.com/" target="_blank">Miro Video Converter</a></li>
</ul>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.8.2.min.js"><\/script>')</script>
<script>
(function($) {
var VideoCue = function(opts) {
this.init(opts);
};
VideoCue.prototype = {
showCuepoint: function (cuepoint) {
/*
* - Hide all the <.cuepoint> DOM elements.
* - Show the <#cuepoint>.
*/
$('.cuepoint').hide();
$('#' + cuepoint).show();
},
getCurrentTime: function () {
return this.video.currentTime;
},
setListener: function (key, value) {
var self = this;
$(this.video).on('timeupdate', function () {
/*
* - If the video current time is equal to or greater than the passed key...
* - AND it is less than the passed key plus a little.
* - Toggle the visibility of the cuepoints via the showCuepoint method.
*/
if (
self.getCurrentTime() >= key &&
self.getCurrentTime() <= ( key + 0.25 ) )
{
self.showCuepoint(value);
}
});
},
buildCuepoint: function (attrs, id) {
/*
* - Count the amount of attributes that have been passed.
* - Set the decrementing value to count
* - Create an #id out of the id passed.
* - Create a <div> to contain the XML info.
*/
var count = attrs.length,
i = count,
ident = 'cue-' + id,
obj = $('<div>', {
'id': ident,
'class': 'cuepoint'
}).hide();
/*
* - Loop through the attributes.
* - If the attribute name equal...
* - ... timeStamp, break that value down into usable data and pass it onto the setListener method.
* - ... thumblink, create an image.
* - else just bung it into a <p>.
* - if the attr value is anything other than false append it to obj.
*/
while( i ) { i -= 1;
var attr = false;
if( attrs[i].name === 'timeStamp' ) {
var timeSplitter = attrs[i].value.split( ':' ),
time = parseFloat( timeSplitter[1] );
this.setListener( time, ident );
}
else if( attrs[i].name === 'thumbLink' ) {
var attr = $('<img>', {
'src': attrs[i].value,
'alt': attrs[i].name
});
}
else {
var attr = $('<p>', {
'class': attrs[i].name,
'text': attrs[i].value
});
}
if(attr) {
attr.appendTo(obj);
}
}
/*
* - Append the newly created markup to the content.
*/
obj.appendTo($(this.content));
},
parseFeed: function (feed) {
/*
* - Create a jQuery object out of the XML feed.
* - Find the relavant data, and count how much there is.
*/
var pointers = $(feed).find( 'cuepoint' ),
count = pointers.length,
i = count;
/*
* - Loop through the data
* - And build markup out of it.
*/
while( i ) { i -= 1;
this.buildCuepoint( pointers[i].attributes, i );
}
},
fetch: function () {
var self = this;
/*
* - Run the jQuery AJAX method
* - Make sure we GET an XML feed based on the URL.
*/
$.ajax({
type: "GET",
url: self.url,
dataType: "xml",
success: function(xml) {
/*
* - If all went well send it on for parsing.
*/
self.parseFeed(xml);
}
});
},
init: function (opts) {
/*
* - Set up some function properties to use in the function.
* - Make sure we have references to the url, video and content parameters that have been passed.
* - Also create a feed object to push data into.
*/
this.url = opts.url;
this.video = document.getElementById(opts.video);
this.content = document.getElementById(opts.content);
/*
* - Now we are ready to run the function methods.
* - Go and fetch the XML.
*/
this.fetch();
}
};
var cues = new VideoCue({
url: 'http://www.mattburrowsportfolio.co.uk/HTML5-Video/assets/cuepoints.xml',
video: 'video',
content: 'content'
});
})(jQuery);
</script>
</body>
</html>