bigscreen-player
Advanced tools
Comparing version 4.2.1 to 4.3.0
{ | ||
"name": "bigscreen-player", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "Simplified media playback for bigscreen devices.", | ||
@@ -5,0 +5,0 @@ "main": "script/bigscreenplayer.js", |
@@ -56,2 +56,11 @@ define('bigscreenplayer/plugins', | ||
callOnAllPlugins('onPlayerInfoUpdated', evt); | ||
}, | ||
onSubtitlesLoadError: function (evt) { | ||
callOnAllPlugins('onSubtitlesLoadError', evt); | ||
}, | ||
onSubtitlesTransformError: function (evt) { | ||
callOnAllPlugins('onSubtitlesTransformError', evt); | ||
}, | ||
onSubtitlesRenderError: function (evt) { | ||
callOnAllPlugins('onSubtitlesRenderError', evt); | ||
} | ||
@@ -58,0 +67,0 @@ } |
@@ -19,3 +19,3 @@ define( | ||
if (captionsURL) { | ||
subtitlesRenderer = new Renderer('playerCaptions', captionsURL, mediaPlayer, container); | ||
subtitlesRenderer = new Renderer('playerCaptions', captionsURL, mediaPlayer, container, autoStart); | ||
container.appendChild(subtitlesRenderer.render()); | ||
@@ -26,6 +26,2 @@ } | ||
if (autoStart) { | ||
start(); | ||
} | ||
function start () { | ||
@@ -32,0 +28,0 @@ if (subtitlesRenderer) { |
@@ -5,8 +5,9 @@ define('bigscreenplayer/subtitles/renderer', | ||
'bigscreenplayer/utils/loadurl', | ||
'bigscreenplayer/subtitles/transformer' | ||
'bigscreenplayer/subtitles/transformer', | ||
'bigscreenplayer/plugins' | ||
], | ||
function (DebugTool, LoadURL, Transformer) { | ||
function (DebugTool, LoadURL, Transformer, Plugins) { | ||
'use strict'; | ||
var Renderer = function (id, url, mediaPlayer) { | ||
var Renderer = function (id, url, mediaPlayer, autoStart) { | ||
var transformedSubtitles; | ||
@@ -25,4 +26,5 @@ var liveItems = []; | ||
transformedSubtitles = Transformer().transformXML(xhr.responseXML); | ||
outputElement.setAttribute('style', transformedSubtitles.baseStyle); | ||
outputElement.style.cssText = transformedSubtitles.baseStyle; | ||
if (autoStart) { | ||
start(); | ||
} | ||
} | ||
@@ -32,2 +34,3 @@ }, | ||
DebugTool.info('Error loading captions data: ' + error); | ||
Plugins.interface.onSubtitlesLoadError(); | ||
} | ||
@@ -41,6 +44,9 @@ }); | ||
function start () { | ||
interval = setInterval(function () { update(); }, 750); | ||
if (outputElement) { | ||
outputElement.style.display = 'block'; | ||
if (transformedSubtitles) { | ||
interval = setInterval(function () { update(); }, 750); | ||
if (outputElement) { | ||
outputElement.style.display = 'block'; | ||
outputElement.setAttribute('style', transformedSubtitles.baseStyle); | ||
outputElement.style.cssText = transformedSubtitles.baseStyle; | ||
} | ||
} | ||
@@ -59,8 +65,21 @@ } | ||
function update () { | ||
if (!mediaPlayer) { | ||
stop(); | ||
try { | ||
if (!mediaPlayer) { | ||
stop(); | ||
} | ||
var time = mediaPlayer.getCurrentTime(); | ||
updateCaptions(time); | ||
confirmCaptionsRendered(); | ||
} catch (e) { | ||
DebugTool.info('Exception while rendering subtitles: ' + e); | ||
Plugins.interface.onSubtitlesRenderError(); | ||
} | ||
} | ||
var time = mediaPlayer.getCurrentTime(); | ||
updateCaptions(time); | ||
function confirmCaptionsRendered () { | ||
if (outputElement && !outputElement.hasChildNodes() && liveItems.length > 0) { | ||
Plugins.interface.onSubtitlesRenderError(); | ||
} | ||
} | ||
@@ -67,0 +86,0 @@ |
define('bigscreenplayer/subtitles/transformer', | ||
[ | ||
'bigscreenplayer/subtitles/timedtext', | ||
'bigscreenplayer/domhelpers' | ||
'bigscreenplayer/domhelpers', | ||
'bigscreenplayer/plugins', | ||
'bigscreenplayer/debugger/debugtool' | ||
], | ||
function (TimedText, DOMHelpers) { | ||
function (TimedText, DOMHelpers, Plugins, DebugTool) { | ||
'use strict'; | ||
@@ -96,60 +98,65 @@ return function () { | ||
function transformXML (xml) { | ||
// Use .getElementsByTagNameNS() when parsing XML as some implementations of .getElementsByTagName() will lowercase its argument before proceding | ||
var conformsToStandardElements = Array.prototype.slice.call(xml.getElementsByTagNameNS('urn:ebu:tt:metadata', 'conformsToStandard')); | ||
var isEBUTTD = conformsToStandardElements && conformsToStandardElements.some(function (node) { | ||
return isEBUDistribution(node.textContent); | ||
}); | ||
try { | ||
// Use .getElementsByTagNameNS() when parsing XML as some implementations of .getElementsByTagName() will lowercase its argument before proceding | ||
var conformsToStandardElements = Array.prototype.slice.call(xml.getElementsByTagNameNS('urn:ebu:tt:metadata', 'conformsToStandard')); | ||
var isEBUTTD = conformsToStandardElements && conformsToStandardElements.some(function (node) { | ||
return isEBUDistribution(node.textContent); | ||
}); | ||
var captionValues = { | ||
ttml: { | ||
namespace: 'http://www.w3.org/2006/10/ttaf1', | ||
idAttribute: 'id' | ||
}, | ||
ebuttd: { | ||
namespace: 'http://www.w3.org/ns/ttml', | ||
idAttribute: 'xml:id' | ||
} | ||
}; | ||
var captionValues = { | ||
ttml: { | ||
namespace: 'http://www.w3.org/2006/10/ttaf1', | ||
idAttribute: 'id' | ||
}, | ||
ebuttd: { | ||
namespace: 'http://www.w3.org/ns/ttml', | ||
idAttribute: 'xml:id' | ||
} | ||
}; | ||
var captionStandard = isEBUTTD ? captionValues.ebuttd : captionValues.ttml; | ||
var styles = _styles; | ||
var styleElements = xml.getElementsByTagNameNS(captionStandard.namespace, 'style'); | ||
var captionStandard = isEBUTTD ? captionValues.ebuttd : captionValues.ttml; | ||
var styles = _styles; | ||
var styleElements = xml.getElementsByTagNameNS(captionStandard.namespace, 'style'); | ||
for (var i = 0; i < styleElements.length; i++) { | ||
var se = styleElements[i]; | ||
var id = se.getAttribute(captionStandard.idAttribute); | ||
var style = elementToStyle(se); | ||
for (var i = 0; i < styleElements.length; i++) { | ||
var se = styleElements[i]; | ||
var id = se.getAttribute(captionStandard.idAttribute); | ||
var style = elementToStyle(se); | ||
if (style) { | ||
styles[id] = style; | ||
if (style) { | ||
styles[id] = style; | ||
} | ||
} | ||
} | ||
var body = xml.getElementsByTagNameNS(captionStandard.namespace, 'body')[0]; | ||
var s = elementToStyle(body); | ||
var ps = xml.getElementsByTagNameNS(captionStandard.namespace, 'p'); | ||
var items = []; | ||
var body = xml.getElementsByTagNameNS(captionStandard.namespace, 'body')[0]; | ||
var s = elementToStyle(body); | ||
var ps = xml.getElementsByTagNameNS(captionStandard.namespace, 'p'); | ||
var items = []; | ||
for (var k = 0, m = ps.length; k < m; k++) { | ||
if (hasNestedTime(ps[k])) { | ||
var tag = ps[k]; | ||
for (var index = 0; index < tag.childNodes.length; index++) { | ||
if (hasAttribute(tag.childNodes[index], 'begin') && hasAttribute(tag.childNodes[index], 'end')) { | ||
// TODO: rather than pass a function, can't we make timedText look after it's style from this point? | ||
items.push(TimedText(tag.childNodes[index], elementToStyle)); | ||
for (var k = 0, m = ps.length; k < m; k++) { | ||
if (hasNestedTime(ps[k])) { | ||
var tag = ps[k]; | ||
for (var index = 0; index < tag.childNodes.length; index++) { | ||
if (hasAttribute(tag.childNodes[index], 'begin') && hasAttribute(tag.childNodes[index], 'end')) { | ||
// TODO: rather than pass a function, can't we make timedText look after it's style from this point? | ||
items.push(TimedText(tag.childNodes[index], elementToStyle)); | ||
} | ||
} | ||
} else { | ||
items.push(TimedText(ps[k], elementToStyle)); | ||
} | ||
} else { | ||
items.push(TimedText(ps[k], elementToStyle)); | ||
} | ||
return { | ||
baseStyle: s, | ||
subtitlesForTime: function (time) { | ||
return items.filter(function (subtitle) { | ||
return subtitle.start < time && subtitle.end > time; | ||
}); | ||
} | ||
}; | ||
} catch (e) { | ||
DebugTool.info('Error transforming captions : ' + e); | ||
Plugins.interface.onSubtitlesTransformError(); | ||
} | ||
return { | ||
baseStyle: s, | ||
subtitlesForTime: function (time) { | ||
return items.filter(function (subtitle) { | ||
return subtitle.start < time && subtitle.end > time; | ||
}); | ||
} | ||
}; | ||
} | ||
@@ -156,0 +163,0 @@ |
define('bigscreenplayer/version', | ||
function () { | ||
return '4.2.1'; | ||
return '4.3.0'; | ||
} | ||
); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
293664
7610