Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPlayer Updates from Mars Game #526

Open
wants to merge 31 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
11ada8a
Got the jPlayer driver to load...
Feb 16, 2015
1722312
Got the new videoManager dropped in. Doesn't break TDG.
Feb 16, 2015
d433d90
Got the changes to the jPlayer model driver merged in. It loads and
Feb 16, 2015
ef5613d
Removed unnecessary method which sets z-index.
Feb 17, 2015
42a1676
Debugged calling "play" along with passing in the URL.
Feb 17, 2015
12a23cc
Got more stuff using "vwf." rather than this.kernel.
Feb 19, 2015
c6b6bae
Now it appears that we can inject divs dynamically?
Feb 19, 2015
93b46ab
Div injection now works (I think?)
Feb 20, 2015
febf021
Changed default names of jPlayer div container and player container BACK
Feb 20, 2015
2603289
Corrected tabs vs spaces in the view driver.
Feb 20, 2015
4de359e
Fix prototype ids for jPlayer
Feb 25, 2015
8eb23d2
Div injection now works (I think?)
Feb 20, 2015
5f1b308
Instead of creating a new mediaObject for every case of file format, …
spencerfrazier Feb 26, 2015
159f2e0
Beginnings of consuming an array of video input URLs is there...
Feb 27, 2015
ad03d93
Adding multi-format support appears to work!
Feb 27, 2015
3a0a2fb
Now, mars-game appears to pass both test cases: playing on a browser …
spencerfrazier Feb 27, 2015
19b4ada
Adding some comments to explain what I commented out.
spencerfrazier Mar 2, 2015
e5f0d43
Removed two unnecessary lines of code.
Mar 2, 2015
63f49b7
Cleaned up the video URL. Now we are ready to test if it's a string or a
Mar 2, 2015
e657c2b
Added check to see if we're parsing a string or an array.
Mar 3, 2015
6610428
Cleand up the code a little bit - in setURL, we now determine if we're
Mar 3, 2015
f17cf61
Fixed spacing and removed some debug code.
Mar 4, 2015
b28b108
Now we are checking if the URL exists.
Apr 20, 2015
0fb486e
Separated setting the URL from playing the video. This should allow us
Apr 20, 2015
324e877
"load" now works in the jPlayer model.
Apr 21, 2015
567290a
Got the load functionality into the jPlayer driver...
Apr 21, 2015
8815fcf
Now we can pre-load the correct cutscenes in the scenario1* series of…
Apr 22, 2015
dae264d
Now the jPlayer driver doesn't set the URL (which may cause a load to
Apr 22, 2015
aefead2
Update jPlayer.js
Apr 23, 2015
f31f6a3
Update jPlayer.js
Apr 23, 2015
cbf764c
kernel prototypes change
Dec 15, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions support/client/lib/vwf.js
Expand Up @@ -405,6 +405,7 @@
{ library: "vwf/view/cesium", active: false },
{ library: "vwf/view/kineticjs", active: false },
{ library: "vwf/view/mil-sym", active: false },
{ library: "vwf/view/jPlayer", linkedLibraries: ["vwf/model/jPlayer.2.7.1/jquery.jplayer.min"], active: false },
{ library: "vwf/view/audio", active: false },
{ library: "vwf/kernel/utility", active: true },
{ library: "vwf/utility", active: true },
Expand Down Expand Up @@ -460,6 +461,7 @@
{ library: "vwf/view/touch", active: false },
{ library: "vwf/view/kineticjs", active: false },
{ library: "vwf/view/mil-sym", active: false },
{ library: "vwf/view/jPlayer", active: false },
{ library: "vwf/view/audio", active: false },
{ library: "vwf/view/webrtc", active: false}
]
Expand Down
165 changes: 124 additions & 41 deletions support/client/lib/vwf/model/jPlayer.js 100644 → 100755
@@ -1,4 +1,4 @@
/// vwf/model/jPlayer.js is a sound driver
/// vwf/model/jPlayer.js is a sound/video driver
///
/// @module vwf/model/jPlayer
/// @requires vwf/model
Expand All @@ -12,16 +12,31 @@ define( [

var modelDriver;
var jPlayerInstanceCreated = false;
// NXM: For some reason, using the format below breaks video!
// var audioManagerProtoId = "http-vwf-example-com-jplayer-audioManager-vwf";
// var videoManagerProtoId = "http-vwf-example-com-jplayer-videoManager-vwf";

var audioManagerProtoId = "http://vwf.example.com/jplayer/audioManager.vwf";
var videoManagerProtoId = "http://vwf.example.com/jplayer/videoManager.vwf";

var jplayerContainerId = "jp_container_1";

return model.load( module, {

// == Module Definition ====================================================================

// -- initialize ---------------------------------------------------------------------------

initialize: function( options ) {

var containerDiv = document.createElement( 'div' );
containerDiv.id = jplayerContainerId;
containerDiv.className = "jp-video jp-video-360p";
var playerDiv = document.createElement( 'div' );
playerDiv.id = "jquery_jplayer_1";
playerDiv.className = "jp-jplayer";
containerDiv.appendChild( playerDiv );
$( "body" ).append(containerDiv);

modelDriver = this;

Expand Down Expand Up @@ -67,7 +82,13 @@ define( [
}
}
return found;
}
},
"videoEndedCallback" : function() {
var mediaManagerID = modelDriver.kernel.find( undefined, "/mediaManager" )[ 0 ];
var videoManagerID = modelDriver.kernel.find( mediaManagerID, "videoManager" ) [ 0 ];
console.log("Video ended callback in driver fired!");
modelDriver.kernel.fireEvent(videoManagerID, "videoEnded");
},
};

// turns on logger debugger console messages
Expand Down Expand Up @@ -120,7 +141,7 @@ define( [
return;
}

var protos = getPrototypes( this.kernel, childExtendsID );
var protos = this.kernel.prototypes( childID );

var isAudioManager = this.state.isAudioManager( protos );
var isVideoManager = this.state.isVideoManager( protos );
Expand Down Expand Up @@ -199,10 +220,17 @@ define( [
setUrl( node, propertyValue );
value = node.url;
break;

case "preload":
setPreload( node, propertyValue );
value = node.preload;
break;

case "loop":
setLoop( node, propertyValue );
value = node.loop;
break;

case "playerDivId":
if ( propertyValue === node.playerDivId ) {
break;
Expand All @@ -215,12 +243,17 @@ define( [
if ( $existingElement.length ) {
node.jPlayerElement = $existingElement;
} else {
node.jPlayerElement = $( "<div/>", {
id: node.playerDivId
} );
$( "body" ).append( node.jPlayerElement );
//Change the existing element to match the new name
var playerDiv = document.createElement( 'div' );
playerDiv.id = node.playerDivId;
if( node.containerDivId ){
$( "#" + node.containerDivId ).append( playerDiv );
} else {
$("#jp_container_1").append( playerDiv );
}
node.jPlayerElement = $( "#" + node.playerDivId );
}
var fileTypes = ( node.managerType === "audio" ) ? "mp3,wav" : "m4v";
var fileTypes = ( node.managerType === "audio" ) ? "mp3,wav" : "m4v,webmv";
node.jPlayerElement.jPlayer( {
ready: function() {
if ( node.url !== undefined ) {
Expand All @@ -229,12 +262,20 @@ define( [
if ( node.loop !== undefined ) {
setLoop( node, node.loop );
}
if ( node.preload !== undefined ) {
setPreload( node, node.preload );
}
if ( node.containerDivId !== undefined ) {
setControlDivId( node, node.containerDivId );
}
},
supplied: fileTypes
supplied: fileTypes,
} );

if ( node.playerDivId ) {
$( "#" + node.playerDivId ).bind( $.jPlayer.event.ended, this.state.videoEndedCallback );
}

value = node.playerDivId;
break;
case "containerDivId":
Expand All @@ -245,6 +286,14 @@ define( [
setPosterImageUrl( node, propertyValue );
value = node.posterImageUrl;
break;
case "playerSize":
setPlayerSize( node, propertyValue );
value = node.playerSize;
break;
case "containerSize":
setContainerSize( node, propertyValue );
value = node.containerSize;
break;
default:
break;
}
Expand Down Expand Up @@ -301,7 +350,6 @@ define( [
return node && node[ propertyName ];
},


// TODO: deletingMethod

// -- callingMethod --------------------------------------------------------------------------
Expand All @@ -323,7 +371,11 @@ define( [
switch( methodName ) {

case "play":
node.jPlayerElement.jPlayer( "play" );
if( node.url ) {
node.jPlayerElement.jPlayer( "play" );
} else {
this.logger.errorx( "No URL given!" );
}
break;

case "pause":
Expand All @@ -334,6 +386,9 @@ define( [
node.jPlayerElement.jPlayer( "stop" );
break;

case "clearMedia":
node.jPlayerElement.jPlayer( "clearMedia" );
break;
}

}
Expand All @@ -342,18 +397,6 @@ define( [

} );

function getPrototypes( kernel, extendsID ) {
var prototypes = [];
var id = extendsID;

while ( id !== undefined ) {
prototypes.push( id );
id = kernel.prototype( id );
}

return prototypes;
}

function setWithPrototypeProperties( proto ) {
if ( proto.url !== null ) {
vwf.setProperty( node.ID, "url", proto.url );
Expand All @@ -372,7 +415,34 @@ define( [
}
}

function setUrl( node, url ) {
function setVideoURL( mediaObj, url ) {
if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) {
mediaObj.m4v = url;
} else if( url.search( ".webm$" ) > -1 ){
mediaObj.webmv = url;
} else {
modelDriver.logger.errorx( "setUrl",
"Unsupported video type for '", url, "'" );
}
}

function setUrl( node, inputUrl ) {

var usingMultiUrls;
var url;
if( inputUrl && ( inputUrl.constructor === Array ) ){
usingMultiUrls = true;
url = inputUrl[ 0 ];
} else {
usingMultiUrls = false;
url = inputUrl;
}

if( node.url && url && ( node.url === url ) ){
console.log("Setting redudant URL! Quitting!");
return;
}

node.url = url;

// If there is no jPlayerElement, there is nothing to do yet so we return.
Expand All @@ -386,31 +456,28 @@ define( [
if ( url ) {

// Construct the media object based on the type of file being passed in
var mediaObject;
var mediaObject = {};

switch ( node.managerType ) {
case "audio":
//TODO: Support multiple URLs for audio.
if ( url.search( "data:audio/mp3" ) === 0 ) {
mediaObject = {
mp3: url
};
medaObject.mp3 = url;
} else if ( url.search( "data:audio/wav" ) === 0 ) {
mediaObject = {
wav: url
};
mediaObject.wav = url;
} else {
modelDriver.logger.errorx( "setUrl",
"Unsupported sound type for '", url, "'" );
}
break;
case "video":
if ( url.search( "data:video/mp4" ) === 0 ) {
mediaObject = {
m4v: url,
poster: node.posterImageUrl
};
mediaObject.poster = node.posterImageUrl;
if( usingMultiUrls ) {
for( var i = 0; i < inputUrl.length; i++ ) {
setVideoURL( mediaObject, inputUrl[ i ] );
}
} else {
modelDriver.logger.errorx( "setUrl",
"Unsupported video type for '", url, "'" );
setVideoURL( mediaObject, url );
}
break;
default:
Expand All @@ -423,6 +490,7 @@ define( [
// Otherwise, clear the current media
if ( mediaObject ) {
node.jPlayerElement.jPlayer( "setMedia", mediaObject );
node.jPlayerElement.jPlayer( "load" );
} else {
node.jPlayerElement.jPlayer( "clearMedia" );
}
Expand All @@ -431,6 +499,14 @@ define( [
}
}

function setPreload( node, preload ) {
node.preload = preload;
if ( node.jPlayerElement ) {
node.jPlayerElement.jPlayer( "option", { preload: preload } );
console.log("Setting preload to: " + preload);
}
}

function setLoop( node, loop ) {
node.loop = loop;
if ( node.jPlayerElement ) {
Expand All @@ -440,9 +516,6 @@ define( [

function setControlDivId( node, containerDivId ) {
node.containerDivId = containerDivId;
if ( node.jPlayerElement ) {
node.jPlayerElement.jPlayer( "option", { cssSelectorAncestor: "#" + containerDivId } );
}
}

function setPosterImageUrl( node, posterImageUrl ) {
Expand All @@ -454,4 +527,14 @@ define( [
} );
}
}

function setPlayerSize( node, playerSize ){
node.playerSize = playerSize;
node.jPlayerElement.jPlayer( "option", "size", {width: playerSize[0], height: playerSize[1]});
}

function setContainerSize( node, containerSize ){
node.containerSize = containerSize;
}

} );