More work on source change
This commit is contained in:
parent
a00407a475
commit
5291bf616e
2
dist/plyr.js
vendored
2
dist/plyr.js
vendored
File diff suppressed because one or more lines are too long
@ -277,6 +277,18 @@
|
|||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepend child
|
||||||
|
function _prependChild(parent, element) {
|
||||||
|
parent.insertBefore(element, parent.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set attributes
|
||||||
|
function _setAttributes(element, attributes) {
|
||||||
|
for(var key in attributes) {
|
||||||
|
element.setAttribute(key, attributes[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Toggle class on an element
|
// Toggle class on an element
|
||||||
function _toggleClass(element, name, state) {
|
function _toggleClass(element, name, state) {
|
||||||
if(element){
|
if(element){
|
||||||
@ -311,6 +323,9 @@
|
|||||||
|
|
||||||
// Get percentage
|
// Get percentage
|
||||||
function _getPercentage(current, max) {
|
function _getPercentage(current, max) {
|
||||||
|
if(current === 0 || max === 0 || isNaN(current) || isNaN(max)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return ((current / max) * 100).toFixed(2);
|
return ((current / max) * 100).toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -838,12 +853,8 @@
|
|||||||
var _seek = function(input) {
|
var _seek = function(input) {
|
||||||
var targetTime = 0;
|
var targetTime = 0;
|
||||||
|
|
||||||
// If no event or time is passed, bail
|
|
||||||
if (typeof input === "undefined") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Explicit position
|
// Explicit position
|
||||||
else if (typeof input === "number") {
|
if (typeof input === "number") {
|
||||||
targetTime = input;
|
targetTime = input;
|
||||||
}
|
}
|
||||||
// Event
|
// Event
|
||||||
@ -868,7 +879,7 @@
|
|||||||
_log("Seeking to " + player.media.currentTime + " seconds");
|
_log("Seeking to " + player.media.currentTime + " seconds");
|
||||||
|
|
||||||
// Special handling for "manual" captions
|
// Special handling for "manual" captions
|
||||||
_seekManualCaptions(targetTime);
|
_seekManualCaptions(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check playing state
|
// Check playing state
|
||||||
@ -997,7 +1008,7 @@
|
|||||||
// Video playing
|
// Video playing
|
||||||
case "timeupdate":
|
case "timeupdate":
|
||||||
case "seeking":
|
case "seeking":
|
||||||
value = _getPercentage(player.media.currentTime, player.media.duration);
|
value = _getPercentage(player.media.currentTime, player.media.duration);
|
||||||
|
|
||||||
// Set seek range value only if it's a "natural" time event
|
// Set seek range value only if it's a "natural" time event
|
||||||
if(event.type == "timeupdate") {
|
if(event.type == "timeupdate") {
|
||||||
@ -1009,7 +1020,7 @@
|
|||||||
// Events from seek range
|
// Events from seek range
|
||||||
case "change":
|
case "change":
|
||||||
case "input":
|
case "input":
|
||||||
value = event.target.value;
|
value = event.target.value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@ -1072,9 +1083,25 @@
|
|||||||
player.media.removeAttribute("src");
|
player.media.removeAttribute("src");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inject a source
|
||||||
|
function _addSource(attributes) {
|
||||||
|
// Create a new <source>
|
||||||
|
var element = document.createElement("source");
|
||||||
|
|
||||||
|
// Set all passed attributes
|
||||||
|
_setAttributes(element, attributes);
|
||||||
|
|
||||||
|
// Inject the new source
|
||||||
|
_prependChild(player.media, element);
|
||||||
|
}
|
||||||
|
|
||||||
// Set source
|
// Set source
|
||||||
function _setSource(source) {
|
function _setSource(source) {
|
||||||
if(source.type && source.src) {
|
if(source.type && source.src) {
|
||||||
|
_addSource(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(source.type && source.src) {
|
||||||
// Check if it's supported first
|
// Check if it's supported first
|
||||||
if(_support(player, source.type)) {
|
if(_support(player, source.type)) {
|
||||||
// Pause playback (webkit freaks out)
|
// Pause playback (webkit freaks out)
|
||||||
@ -1103,11 +1130,27 @@
|
|||||||
else {
|
else {
|
||||||
_log("No support for: " + source.src + " [" + source.type + "]");
|
_log("No support for: " + source.src + " [" + source.type + "]");
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update source
|
// Update source
|
||||||
function _parseSource(sources) {
|
function _parseSource(sources) {
|
||||||
|
// Pause playback (webkit freaks out)
|
||||||
|
_pause();
|
||||||
|
|
||||||
|
// Restart
|
||||||
|
_seek();
|
||||||
|
|
||||||
|
// Update the UI
|
||||||
|
_checkPlaying();
|
||||||
|
|
||||||
|
// Remove current sources
|
||||||
|
_removeSources();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// If a single source object is provided
|
// If a single source object is provided
|
||||||
// ({ src: "//cdn.selz.com/plyr/1.0/movie.webm", type: "video/webm" })
|
// ({ src: "//cdn.selz.com/plyr/1.0/movie.webm", type: "video/webm" })
|
||||||
if(typeof sources === "object" && sources.constructor !== Array) {
|
if(typeof sources === "object" && sources.constructor !== Array) {
|
||||||
@ -1117,15 +1160,24 @@
|
|||||||
|
|
||||||
// An array of source objects
|
// An array of source objects
|
||||||
// Check if a source exists, use that or set the "src" attribute?
|
// Check if a source exists, use that or set the "src" attribute?
|
||||||
// [{ src: "path/to/src.mp4", type: "video/mp4" },{ src: "path/to/src.webm", type: "video/webm" }]
|
// ([{ src: "path/to/src.mp4", type: "video/mp4" },{ src: "path/to/src.webm", type: "video/webm" }])
|
||||||
else if (sources.constructor === Array) {
|
else if (sources.constructor === Array) {
|
||||||
for (var index in sources) {
|
for (var index in sources) {
|
||||||
_setSource(sources[index]);
|
_setSource(sources[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not an object or an array
|
|
||||||
else {
|
|
||||||
_log("Bad source format...");
|
|
||||||
|
// Reset time display
|
||||||
|
_timeUpdate();
|
||||||
|
|
||||||
|
// Re-load sources
|
||||||
|
player.media.load();
|
||||||
|
|
||||||
|
// Play if autoplay attribute is present
|
||||||
|
if(player.media.getAttribute("autoplay") !== null) {
|
||||||
|
_play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user