Skip to content
This repository was archived by the owner on Jan 31, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 64 additions & 49 deletions public/src/core/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"core/eventmanager",
"core/track",
"core/popcorn-wrapper",
"util/uri"
"util/uri",
"util/mediatypes"
],
function( Logger, EventManager, Track, PopcornWrapper, URI ) {
function( Logger, EventManager, Track, PopcornWrapper, URI, MediaTypes ) {

var MEDIA_ELEMENT_SAFETY_POLL_INTERVAL = 500,
MEDIA_ELEMENT_SAFETY_POLL_ATTEMPTS = 10;
Expand Down Expand Up @@ -580,15 +581,76 @@
i, l,
fallbacks = [],
sources = [];

function doImportTracks() {
if ( importData.tracks ) {
var importTracks = importData.tracks;
if( Array.isArray( importTracks ) ) {
for ( i = 0, l = importTracks.length; i < l; ++i ) {
newTrack = new Track();
newTrack.json = importTracks[ i ];
_this.addTrack( newTrack );
newTrack.updateTrackEvents();
}
// Backwards comp for old base media.
// Insert previous base media as a sequence event as the last track.
if ( importData.url && _duration >= 0 ) {
var firstSource;

// If sources is a single array and of type null player, don't bother making a sequence.
if ( url.length > 1 || !( /#t=\d*,?\d+?/ ).test( url[ 0 ] ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this use mediaTypes.checkUrl

// grab first source as main source.
sources.push( URI.makeUnique( url.shift() ).toString() );
for ( i = 0; i < url.length; i++ ) {
fallbacks.push( URI.makeUnique( url[ i ] ).toString() );
}

firstSource = sources[ 0 ];
newTrack = new Track();
_this.addTrack( newTrack );
newTrack.addTrackEvent({
type: "sequencer",
popcornOptions: {
start: 0,
end: _duration,
source: sources,
title: URI.stripUnique( firstSource ).path,
fallback: fallbacks,
duration: _duration,
target: "video-container"
}
});
_clipData[ firstSource ] = firstSource;
}
}
} else if ( console ) {
console.warn( "Ignoring imported track data. Must be in an Array." );
}
}
}

if( importData.name ) {
_name = importData.name;
}
if( importData.target ){
_this.target = importData.target;
}

url = importData.url;
if ( !Array.isArray( url ) ) {
url = [ url ];
}

if ( importData.duration >= 0 ) {
_duration = importData.duration;
_this.url = "#t=," + _duration;
doImportTracks();
} else {
MediaTypes.getMetaData( url[ 0 ], function success( data ) {
_duration = data.duration;
_this.url = "#t=," + _duration;
doImportTracks();
});
}
if ( importData.clipData ) {
var tempClipData = importData.clipData,
Expand All @@ -606,53 +668,6 @@
}
}
}
if( importData.tracks ){
var importTracks = importData.tracks;
if( Array.isArray( importTracks ) ) {
for ( i = 0, l = importTracks.length; i < l; ++i ) {
newTrack = new Track();
newTrack.json = importTracks[ i ];
_this.addTrack( newTrack );
newTrack.updateTrackEvents();
}
// Backwards comp for old base media.
// Insert previous base media as a sequence event as the last track.
if ( importData.url && _duration >= 0 ) {
var firstSource;
url = importData.url;
if ( !Array.isArray( url ) ) {
url = [ url ];
}
// If sources is a single array and of type null player, don't bother making a sequence.
if ( url.length > 1 || !( /#t=\d*,?\d+?/ ).test( url[ 0 ] ) ) {
// grab first source as main source.
sources.push( URI.makeUnique( url.shift() ).toString() );
for ( i = 0; i < url.length; i++ ) {
fallbacks.push( URI.makeUnique( url[ i ] ).toString() );
}

firstSource = sources[ 0 ];
newTrack = new Track();
_this.addTrack( newTrack );
newTrack.addTrackEvent({
type: "sequencer",
popcornOptions: {
start: 0,
end: _duration,
source: sources,
title: URI.stripUnique( firstSource ).path,
fallback: fallbacks,
duration: _duration,
target: "video-container"
}
});
_clipData[ firstSource ] = firstSource;
}
}
} else if ( console ) {
console.warn( "Ignoring imported track data. Must be in an Array." );
}
}
},
enumerable: true
},
Expand Down
12 changes: 11 additions & 1 deletion public/src/util/mediatypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ define( [ "util/xhr", "util/uri" ],
var REGEX_MAP = {
youtube: /(?:https?:\/\/www\.|https?:\/\/|www\.|\.|^)youtu/,
vimeo: /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/,
soundcloud: /(?:https?:\/\/www\.|https?:\/\/|www\.|\.|^)(soundcloud)/
soundcloud: /(?:https?:\/\/www\.|https?:\/\/|www\.|\.|^)(soundcloud)/,
// supports #t=<start>,<duration>
// where start or duration can be: X, X.X or XX:XX
"null": /^\s*#t=(?:\d*(?:(?:\.|\:)?\d+)?),?(\d+(?:(?:\.|\:)\d+)?)\s*$/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unfortunate regex. Not sure if there is a similar way, but if there is, we should update it.

},
YOUTUBE_EMBED_DISABLED = "Embedding of this YouTube video is disabled",
SOUNDCLOUD_EMBED_DISABLED = "Embedding of this SoundCloud video is disabled";
Expand Down Expand Up @@ -147,6 +150,13 @@ define( [ "util/xhr", "util/uri" ],
title: respData.title
});
});
} else if ( type === "null" ) {
successCallback({
source: baseUrl,
type: type,
title: baseUrl,
duration: REGEX_MAP[ "null" ].exec( baseUrl )[ 1 ]
});
} else if ( type === "html5" ) {
videoElem = document.createElement( "video" );
videoElem.addEventListener( "loadedmetadata", function() {
Expand Down