зеркало из https://github.com/mozilla/popcorn-js.git
[#289] Documented, expanded tests
This commit is contained in:
Родитель
818ce17b49
Коммит
1cb1e319be
|
@ -11,8 +11,12 @@
|
|||
<body>
|
||||
<h1 id="qunit-header">Popcorn 0.3 TTXT parser Plug-in Demo</h1>
|
||||
<p>Subtitles are processed from <a href="data/data.TTXT">here</a></p>
|
||||
<p>From 2.4 to 5.2 seconds, "[Background Music Playing]" is shown</p>
|
||||
<p>From 15.712 to 17.399 seconds, "Heay!!" is shown</p>
|
||||
<p>From 25.712 to 30.399 seconds, "[Bird noises]" is shown</p>
|
||||
<div>
|
||||
<video id='video' data-timeline-sources="data/data.TTXT"
|
||||
<video id='video'
|
||||
data-timeline-sources="data/data.TTXT"
|
||||
controls
|
||||
width= '250px'
|
||||
poster="../../test/poster.png">
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
};
|
||||
|
||||
// Simple function to convert HH:MM:SS.MMM to SS.MMM
|
||||
// Assume valid, returns 0 on error
|
||||
var toSeconds = function(t_in) {
|
||||
var t = t_in.split(":");
|
||||
var time = 0;
|
||||
|
@ -44,20 +45,21 @@
|
|||
|
||||
// this is where things actually start
|
||||
var node = data.xml.lastChild.lastChild; // Last Child of TextStreamHeader
|
||||
var lastStart = 3.4028235e+38;
|
||||
var lastStart = Number.MAX_VALUE;
|
||||
var cmds = [];
|
||||
|
||||
// Work backwards through DOM, processing TextSample nodes
|
||||
while (node) {
|
||||
if ( node.nodeType === 1 && node.nodeName === "TextSample") {
|
||||
var sub = {};
|
||||
sub.start = toSeconds(node.getAttribute('sampleTime'));
|
||||
sub.text = node.getAttribute('text');
|
||||
|
||||
// Infer end time, ms accuracy
|
||||
sub.end = lastStart;
|
||||
// Infer end time from prior element, ms accuracy
|
||||
sub.end = lastStart - 0.001;
|
||||
|
||||
cmds.push( createTrack("subtitle", sub) );
|
||||
lastStart = sub.start - 0.001;
|
||||
lastStart = sub.start;
|
||||
}
|
||||
node = node.previousSibling;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,47 @@
|
|||
test("Popcorn 0.3 TTXT Parser Plugin", function () {
|
||||
|
||||
var expects = 8,
|
||||
var expects = 0,
|
||||
count = 0,
|
||||
sub = {},
|
||||
numSubs = 0,
|
||||
poppercorn = Popcorn( "#video" ),
|
||||
subs = { // Expected values
|
||||
"0": "",
|
||||
"2.4": "[Background Music Playing]",
|
||||
"5.2": "",
|
||||
"15.712": "Heay!!",
|
||||
"17.399": "",
|
||||
"25.712": "[Bird noises]",
|
||||
"30.399": ""
|
||||
};
|
||||
subs = [ // Expected values
|
||||
{
|
||||
start: 0,
|
||||
end: 2.399,
|
||||
text: ""
|
||||
},
|
||||
{
|
||||
start: 2.4,
|
||||
end: 5.199,
|
||||
text: "[Background Music Playing]"
|
||||
},
|
||||
{
|
||||
start: 5.2,
|
||||
end: 15.711,
|
||||
text: ""
|
||||
},
|
||||
{
|
||||
start: 15.712,
|
||||
end: 17.398,
|
||||
text: "Heay!!"
|
||||
},
|
||||
{
|
||||
start: 17.399,
|
||||
end: 25.711,
|
||||
text: ""
|
||||
},
|
||||
{
|
||||
start: 25.712,
|
||||
end: 30.398,
|
||||
text: "[Bird noises]"
|
||||
},
|
||||
{
|
||||
start: 30.399,
|
||||
end: Number.MAX_VALUE,
|
||||
text: ""
|
||||
}
|
||||
];
|
||||
|
||||
function plus() {
|
||||
if ( ++count === expects ) {
|
||||
|
@ -22,6 +51,7 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
|
|||
|
||||
poppercorn.parseTTXT(document.getElementById('video').getAttribute('data-timeline-sources'));
|
||||
|
||||
expects = subs.length*3+1;
|
||||
expect(expects);
|
||||
|
||||
stop( 5000 );
|
||||
|
@ -30,15 +60,22 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
|
|||
setTimeout(function () {
|
||||
Popcorn.forEach(poppercorn.getTrackEvents(), function(evt) {
|
||||
if(evt._natives.type === "subtitle") {
|
||||
numSubs++;
|
||||
equals(subs[evt.start.toString()], evt.text , "Correct text" );
|
||||
sub = subs[numSubs++];
|
||||
|
||||
equals(sub.end, evt.end , "Correct end" );
|
||||
plus();
|
||||
|
||||
equals(sub.start, evt.start , "Correct start" );
|
||||
plus();
|
||||
|
||||
equals(sub.text, evt.text , "Correct text" );
|
||||
plus();
|
||||
}
|
||||
});
|
||||
|
||||
equals(7, numSubs , "Correctly parsed all subs" );
|
||||
equals(subs.length, numSubs , "Correctly parsed all subs" );
|
||||
plus();
|
||||
|
||||
}, 1500);
|
||||
}, 500);
|
||||
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче