Skip to content
This repository was archived by the owner on Jan 31, 2018. It is now read-only.
Open
Changes from 2 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
110 changes: 61 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,6 +581,57 @@
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;
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 ] ) ) {

Copy link
Copy Markdown
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;
}
Expand All @@ -589,6 +641,13 @@
if ( importData.duration >= 0 ) {
_duration = importData.duration;
_this.url = "#t=," + _duration;
doImportTracks();
} else {
MediaTypes.getMetaData( importData.url[ 0 ], function success( data ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is importData.url isn't an array at this point? We have code at that checks if it is or not. We might need to move this down here to happen before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think Matt is right here.

I think we can do better to move this check lower down.

_duration = data.duration;
_this.url = "#t=," + _duration;
doImportTracks();
});
}
if ( importData.clipData ) {
var tempClipData = importData.clipData,
Expand All @@ -606,53 +665,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