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

Extra functionality added for extensive use. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
98 changes: 78 additions & 20 deletions jquery.brightcove-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright © 2013 Carmine Olivo ([email protected])
* Released under the (http://co.mit-license.org/) MIT license
*
* @requires
* @require
* BrightcoveExperiences (http://admin.brightcove.com/js/BrightcoveExperiences.js)
* jQuery (http://jquery.com/download/)
*
Expand Down Expand Up @@ -57,16 +57,16 @@ var

this.each( function() {
var $container = $( this ),
data = $container.data( "brightcoveVideo" ),
usrTemplateLoadHandler,
usrTemplateReadyHandler,
usrTemplateErrorHandler,
playerObject,
params;
data = $container.data( "brightcoveVideo" ),
usrTemplateLoadHandler,
usrTemplateReadyHandler,
usrTemplateErrorHandler,
playerObject,
params;

// if the player hasn't been initialized yet
if ( ! data ) {
params = $.extend( {
params = $.extend( {
/*
autoStart: null,
bgcolor: null,
Expand All @@ -87,7 +87,7 @@ var
isUI: true,
isVid: true,
wmode: "transparent"
}, options );
}, options );

brightcove.JBVData.onTemplateLoad[ "player" + brightcove.JBVData.countPlayers ] = function( experienceID ) {
data.experienceID = experienceID;
Expand All @@ -98,8 +98,13 @@ var
data.player = brightcove.getExperience( experienceID );
data.isSmartPlayer = false;
}
data.videoPlayer = data.player.getModule( brightcove.api.modules.APIModules.VIDEO_PLAYER );
data.advertising = data.player.getModule( brightcove.api.modules.APIModules.ADVERTISING );
data.auth = data.player.getModule( brightcove.api.modules.APIModules.AUTH );
data.captions = data.player.getModule( brightcove.api.modules.APIModules.CAPTIONS );
data.content = data.player.getModule( brightcove.api.modules.APIModules.CONTENT );
data.cuePoints = data.player.getModule( brightcove.api.modules.APIModules.CUE_POINTS );
data.experience = data.player.getModule( brightcove.api.modules.APIModules.EXPERIENCE );
data.videoPlayer = data.player.getModule( brightcove.api.modules.APIModules.VIDEO_PLAYER );

$container.data( "brightcoveVideo", data );

Expand Down Expand Up @@ -158,11 +163,11 @@ var

return this.each( function() {
var $this = $( this ),
data = $this.data( "brightcoveVideo" ),
$experience = $( "#" + data.experienceID ),
isSmartPlayer = data.isSmartPlayer,
experience = data.experience,
target = data.target;
data = $this.data( "brightcoveVideo" ),
$experience = $( "#" + data.experienceID ),
isSmartPlayer = data.isSmartPlayer,
experience = data.experience,
target = data.target;

// Namespacing FTW :)
$( window ).unbind( ".brightcoveVideo" );
Expand Down Expand Up @@ -218,7 +223,7 @@ var
onMediaEvent: function( event_name, handler, priority ) {
return this.each( function() {
var data = $( this ).data( "brightcoveVideo" ),
events = data.isSmartPlayer ? brightcove.api.events.MediaEvent : BCMediaEvent;
events = data.isSmartPlayer ? brightcove.api.events.MediaEvent : BCMediaEvent;

data.videoPlayer
.addEventListener( events[event_name], handler, priority );
Expand All @@ -231,7 +236,7 @@ var
onExperienceEvent: function( event_name, handler, priority ) {
return this.each( function() {
var data = $( this ).data( "brightcoveVideo" ),
events = data.isSmartPlayer ? brightcove.api.events.ExperienceEvent : BCExperienceEvent;
events = data.isSmartPlayer ? brightcove.api.events.ExperienceEvent : BCExperienceEvent;

data.experience
.addEventListener( events[event_name], handler, priority );
Expand All @@ -244,7 +249,7 @@ var
onCuePointEvent: function( event_name, handler, priority ) {
return this.each( function() {
var data = $( this ).data( "brightcoveVideo" ),
events = data.isSmartPlayer ? brightcove.api.events.CuePointEvent : BCCuePointEvent;
events = data.isSmartPlayer ? brightcove.api.events.CuePointEvent : BCCuePointEvent;

data.videoPlayer
.addEventListener( events[event_name], handler, priority );
Expand All @@ -259,8 +264,8 @@ var

this.each( function() {
var $this = $( this ),
data = $this.data( "brightcoveVideo" ),
$experience, position, $overlay;
data = $this.data( "brightcoveVideo" ),
$experience, position, $overlay;

if ( ! data.overlay ) {
$experience = $( "#" + data.experienceID );
Expand Down Expand Up @@ -326,6 +331,59 @@ var
} );
},

/**
* Sets audio volume level (0-1).
*
* @param {number} time The time in seconds to seek to
*/
setVolume: function( amount ) {
return this.each( function() {
var videoPlayer;

if (typeof amount === "number") {
videoPlayer = $( this ).data( "brightcoveVideo" ).videoPlayer;

amount = Math.min(amount, 1); //sanitize
amount = Math.max(amount, 0);

if (videoPlayer.setVolume) {
videoPlayer.setVolume( amount );
}
}
} );
},

getVolume: function () {
var amount = null;

this.each( function () {
var videoPlayer;

videoPlayer = $( this ).data( "brightcoveVideo" ).videoPlayer;

if (videoPlayer.getVolume) {
amount = videoPlayer.getVolume( );
}
} );

return amount;
},

/**
* Toggle enabling of captions
* @param enabled
* @returns {*|each|HTMLElement|each|Array|Object|String|each}
*/
setCaptionsEnabled: function( enabled ) {
return this.each( function() {
var captions = $( this ).data( "brightcoveVideo" ).captions;

if (captions.setCaptionsEnabled) {
captions.setCaptionsEnabled( enabled );
}
} );
},

/**
* Sets the pixel dimensions for the experience.
*
Expand Down