| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| |
| <script src=../media-file.js></script> |
| <script src=../video-test.js></script> |
| <script> |
| |
| var addtrackEventCount = 0; |
| var seekedCount = 0; |
| var cuesStarts = []; |
| |
| function trackAdded(event) |
| { |
| consoleWrite("EVENT(" + event.type + ")"); |
| compareTracks("event.track", "video.textTracks[" + addtrackEventCount + "]"); |
| ++addtrackEventCount; |
| consoleWrite(""); |
| } |
| |
| function compareTracks(track1, track2) |
| { |
| var equal = (eval(track1) == eval(track2)); |
| reportExpected(equal, track1, "==", track2, track1); |
| } |
| |
| function pollProgress() |
| { |
| switch (seekedCount) { |
| case 1: |
| video.currentTime = 0; |
| run("video.play()"); |
| consoleWrite(""); |
| break; |
| |
| case 2: |
| if (video.currentTime < 2 || inbandTrack1.cues.length <= 5) |
| return; |
| |
| // Collect the start times of all cues, seek back to the beginning and play |
| // the same segment of the video file. |
| run("video.pause()"); |
| for (var i = 0; i < inbandTrack1.cues.length; ++i) |
| cuesStarts.push(inbandTrack1.cues[i].startTime); |
| video.currentTime = 0; |
| run("video.play()"); |
| consoleWrite(""); |
| break; |
| |
| case 3: |
| if (inbandTrack1.cues.length < cuesStarts.length) |
| break; |
| |
| run("video.pause()"); |
| var failure = false; |
| for (var i = 0; i < cuesStarts.length; ++i) { |
| if (cuesStarts[i] != inbandTrack1.cues[i].startTime) { |
| failure = true; |
| break; |
| } |
| } |
| |
| if (failure) { |
| consoleWrite("<br><i>** FAIL<" + "/i>"); |
| for (var i = 0; i < cuesStarts.length; ++i) { |
| var oldStart = cuesStarts[i]; |
| var newStart = inbandTrack1.cues[i].startTime; |
| consoleWrite("Cue " + i + " start time was: " + oldStart + ", is now: " + newStart); |
| } |
| consoleWrite(""); |
| } |
| |
| endTest(); |
| break; |
| } |
| } |
| |
| function tracksChanged() |
| { |
| setInterval(pollProgress, 100); |
| |
| // We seek to time 0.1 and then back to 0 before starting playback to make it more likely |
| // that the media engine will process the initial media samples and deliver the first |
| // inband cues to WebKit. |
| video.currentTime = 0.1; |
| } |
| |
| function canplaythrough() |
| { |
| video.textTracks.removeEventListener("addtrack", trackAdded, false); |
| |
| consoleWrite("<br><i>** Check initial in-band track states<" + "/i>"); |
| testExpected("video.textTracks.length", 1); |
| run("inbandTrack1 = video.textTracks[0]"); |
| testExpected("inbandTrack1.mode", "disabled"); |
| testExpected("inbandTrack1.cues", null); |
| testExpected("inbandTrack1.language", "en"); |
| testExpected("inbandTrack1.kind", "captions"); |
| waitForEventOn(video.textTracks, 'change', tracksChanged); |
| |
| consoleWrite(""); |
| |
| video.addEventListener("seeked", function() { ++seekedCount; }); |
| run("inbandTrack1.mode = 'showing'"); |
| } |
| |
| function setup() |
| { |
| findMediaElement(); |
| video.textTracks.addEventListener("addtrack", trackAdded); |
| video.src = '../content/counting-captioned.mov'; |
| waitForEvent('canplaythrough', canplaythrough); |
| } |
| |
| </script> |
| </head> |
| <body onload="setup()"> |
| <video controls></video> |
| <p>In-band text tracks.</p> |
| </body> |
| </html> |