Skip to content

Commit

Permalink
Add a JWPlayer Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
screeley committed Apr 15, 2014
1 parent 6ff9b95 commit 3c786c5
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 3 deletions.
119 changes: 119 additions & 0 deletions src/adapters/jwplayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*globals playerjs:true*/

//http://www.longtailvideo.com/support/jw-player/28851/javascript-api-reference
playerjs.JWPlayerAdapter = function(player){
if (!(this instanceof playerjs.JWPlayerAdapter)) {
return new playerjs.JWPlayerAdapter(player);
}
this.init(player);
};

playerjs.JWPlayerAdapter.prototype.init = function(player){

playerjs.assert(player, 'playerjs.JWPlayerAdapter requires a player object');

// Set up the actual receiver
var receiver = this.receiver = new playerjs.Receiver();

// JWPlayer doesn't have a seLoop, so we can do it ourself.
this.looped = false;

/* EVENTS */
player.onPause(function(){
receiver.emit('pause');
});

player.onPlay(function(){
receiver.emit('play');
});

player.onTime(function(e){
var seconds = e.position,
duration = e.duration;

if (!seconds || !duration){
return false;
}

var value = {
seconds: seconds,
duration: duration
};
receiver.emit('timeupdate', value);
});

var self = this;
player.onComplete(function(){
// Fake the looping
if (self.looped === true){
// By default jwplayer seeks after play.
player.seek(0);
} else {
// Else throw the ended event.
receiver.emit('ended');
}
});

player.onError(function(){
receiver.emit('error');
});


/* METHODS */
receiver.on('play', function(){
player.play(true);
});

receiver.on('pause', function(){
player.pause(true);
});

receiver.on('getPaused', function(callback){
callback(player.getState() !== 'PLAYING');
});

receiver.on('getCurrentTime', function(callback){
callback(player.getPosition());
});

receiver.on('setCurrentTime', function(value){
player.seek(value);
});

receiver.on('getDuration', function(callback){
callback(player.getDuration());
});

receiver.on('getVolume', function(callback){
callback(player.getVolume());
});

receiver.on('setVolume', function(value){
player.setVolume(value);
});

receiver.on('mute', function(){
player.setMute(true);
});

receiver.on('unmute', function(){
player.setMute(false);
});

receiver.on('getMuted', function(callback){
callback(player.getMute() === true);
});

receiver.on('getLoop', function(callback){
callback(this.looped);
}, this);

receiver.on('setLoop', function(value){
this.looped = value;
}, this);
};

/* Call when the video.js is ready */
playerjs.JWPlayerAdapter.prototype.ready = function(){
this.receiver.ready();
};
2 changes: 1 addition & 1 deletion src/adapters/sublime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ playerjs.SublimeAdapter.prototype.methods = [

playerjs.SublimeAdapter.prototype.init = function(player){

playerjs.assert(player, 'playerjs.VideoJSReceiver requires a player object');
playerjs.assert(player, 'playerjs.SublimeAdapter requires a player object');

// Set up the actual receiver
var receiver = this.receiver = new playerjs.Receiver(this.events, this.methods);
Expand Down
37 changes: 37 additions & 0 deletions test/jwplayer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
html,body {
padding:0;
margin:0;
width:100%;
height:100%;
}
</style>
</head>
<body>
<div id="video"></div>
<script src="http://jwpsrv.com/library/v71rLsS8EeOxRSIACi0I_Q.js"></script>
<script src="/dist/player.js"></script>

<script type="text/javascript">
jwplayer("video").setup({
file: "/lib/videos/demo.mp4",
height: '100%',
width: '100%'
});

var adapter = new playerjs.JWPlayerAdapter(jwplayer());

jwplayer().onReady(function(){
adapter.ready();
});
</script>

</script>
</body>
</html>
1 change: 0 additions & 1 deletion test/sublime.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<meta charset="utf-8">
<link href="//vjs.zencdn.net/4.2/video-js.css" rel="stylesheet">
</head>
<body>
<video id="video" class="sublime"
Expand Down
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var FRAMES = [
'http://localhost.com:8003/test/mock.html',
'http://localhost.com:8003/test/html.html',
'http://localhost.com:8003/test/video.html',
'http://localhost.com:8003/test/sublime.html'
'http://localhost.com:8003/test/sublime.html',
'http://localhost.com:8003/test/jwplayer.html'
];

var isNumber= function(obj){
Expand Down

0 comments on commit 3c786c5

Please sign in to comment.