Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

addPlugin function is deprecated. Changed .tracks plugin

  • Loading branch information...
commit c1a8b871493cd448c67a1b670ea3a77a072176df 1 parent c7a9b29
@oscarotero authored
View
9 README
@@ -1,13 +1,14 @@
-$media jQuery plugin (v.1.2)
+$media jQuery plugin (v.1.3)
-2011. Created by Oscar Otero (http://oscarotero.com / http://anavallasuiza.com)
+2012. Created by Oscar Otero (http://oscarotero.com / http://anavallasuiza.com)
-$media is a jQuery plugin that allows manage html5 video and audio elements: properties, events, timeline, etc.
+$media is a jQuery plugin that allows manage html5 video and audio elements: properties, events, etc.
Available plugins:
+$media.timeline: allows synchronize content with the timeline of the video/audio
$media.tracks: allows synchronize webSrt files (subtitles, chapters, descriptions, etc) with video and audio elements
$media.toCanvas: export the video to canvas and allowing pixel manipulation in real time
-$media.syncwith: allows synchronize two or more media elements
+$media.sync: allows synchronize two or more media elements
$media is released under the GNU Affero GPL version 3.
More information at http://www.gnu.org/licenses/agpl-3.0.html
View
3  demos/subtitles.html
@@ -16,14 +16,13 @@
$(document).ready(function () {
video = $.media('video');
- video.addPlugin('tracks');
//Load and unload the subtitles
$('#change_subtitles input:checkbox').click(function () {
var value = $(this).val();
if (!subtitles[value]) {
- subtitles[value] = video.tracks.load(value);
+ subtitles[value] = video.getTrack(value);
}
if ($(this).prop('checked')) {
View
27 source/jquery.media.js
@@ -948,33 +948,6 @@
}
- /**
- * function addPlugin (name, [config])
- *
- * Add a plugin to current $media instance
- */
- $media.prototype.addPlugin = function (name, config) {
- var plugins = name;
-
- if (typeof plugins != 'object') {
- plugins = {};
- plugins[name] = config;
- }
-
- var that = this;
-
- $.each(plugins, function (plugin_name, plugin_config) {
- if (!$media.plugins[plugin_name]) {
- console.error('The plugin "' + plugin_name + '" is not registered');
- return false;
- }
-
- that[plugin_name] = new $media.plugins[plugin_name](that, plugin_config);
- });
-
- return this;
- }
-
/**
* function jQuery.media (selector, properties)
View
120 source/jquery.media.sync.js
@@ -48,85 +48,87 @@
});
}
- $media.extend('syncWith', function (media, offset) {
- offset = offset ? offset.toSeconds() : 0;
+ $media.extend({
+ syncWith: function (media, offset) {
+ offset = offset ? offset.toSeconds() : 0;
+
+ if ($.isArray(this.sync)) {
+ this.sync.push({
+ media: media,
+ offset: offset
+ });
+
+ return this;
+ }
+
+ this.sync = [];
- if ($.isArray(this.sync)) {
this.sync.push({
media: media,
offset: offset
});
- return this;
- }
+ this.bind('mediaPlay mediaPause mediaPlaying', synchronize);
- this.sync = [];
-
- this.sync.push({
- media: media,
- offset: offset
- });
-
- this.bind('mediaPlay mediaPause mediaPlaying', synchronize);
-
- this.syncReady(function () {
- $.proxy(synchronize, this)(null, this.time());
- });
-
- return this;
- });
+ this.syncReady(function () {
+ $.proxy(synchronize, this)(null, this.time());
+ });
- $media.extend('unSyncWith', function (media) {
- if (!media) {
- this.sync = [];
- } else if ($.isArray(this.sync) && this.sync.length) {
- for (var i = 0; i < this.sync.length; i++) {
- if (this.sync[i].media.$element.is(media.$element)) {
- this.sync.splice(i, 1);
- break;
+ return this;
+ },
+
+ unSyncWith: function (media) {
+ if (!media) {
+ this.sync = [];
+ } else if ($.isArray(this.sync) && this.sync.length) {
+ for (var i = 0; i < this.sync.length; i++) {
+ if (this.sync[i].media.$element.is(media.$element)) {
+ this.sync.splice(i, 1);
+ break;
+ }
}
+ } else {
+ return this;
}
- } else {
- return this;
- }
- if (!this.sync.length) {
- this.unbind('mediaPlay mediaPause mediaPlaying', synchronize);
- }
+ if (!this.sync.length) {
+ this.unbind('mediaPlay mediaPause mediaPlaying', synchronize);
+ }
- return this;
- });
+ return this;
+ },
- $media.extend('syncReady', function (state, fn) {
- if (typeof state != 'number') {
- fn = state;
- state = 3;
- }
+ syncReady: function (state, fn) {
+ if (typeof state != 'number') {
+ fn = state;
+ state = 3;
+ }
- var medias = [this];
+ var medias = [this];
- $.each(this.sync, function (i, media) {
- medias.push(media.media);
- });
+ $.each(this.sync, function (i, media) {
+ medias.push(media.media);
+ });
- if (!$.isFunction(fn)) {
- return syncReady(medias, state);
- }
+ if (!$.isFunction(fn)) {
+ return syncReady(medias, state);
+ }
- if (syncReady(medias, state)) {
- $.proxy(fn, this)();
- } else {
- var that = this;
- var ready = function () {
- if (syncReady(medias, state)) {
- clearInterval(interval_ready);
- $.proxy(fn, that)();
+ if (syncReady(medias, state)) {
+ $.proxy(fn, this)();
+ } else {
+ var that = this;
+ var ready = function () {
+ if (syncReady(medias, state)) {
+ clearInterval(interval_ready);
+ $.proxy(fn, that)();
+ }
}
+
+ var interval_ready = setInterval($.proxy(ready, that), 13);
}
- var interval_ready = setInterval($.proxy(ready, that), 13);
+ return this;
}
-
- return this;
});
})(jQuery);
View
47 source/jquery.media.tracks.js
@@ -274,46 +274,19 @@
};
+ $media.extend('getTrack', function (element, settings) {
+ var $element = $(element).eq(0);
- //Track plugin
- $media.plugins.tracks = function (media, settings) {
- this.media = media;
- this.settings = {};
-
- settings = settings || {};
- var kinds = ['subtitles', 'chapters', 'descriptions', 'captions'];
-
- for (var i in kinds) {
- this.settings[kinds[i]] = {};
-
- if (settings[kinds[i]]) {
- $.extend(this.settings[kinds[i]], settings[kinds[i]]);
- }
+ if (!$element.is('track')) {
+ return false;
}
- }
-
- $media.plugins.tracks.prototype = {
-
- /**
- * function load (element, [settings])
- *
- * Loads a track from the video and returns the track object
- */
- load: function (element, settings) {
- var $element = $(element).eq(0);
- var kind = $element.attr('kind');
-
- if (!$element.is('track') || !this.settings[kind]) {
- return false;
- }
- if ($.isFunction(settings)) {
- settings = {load: settings};
- }
+ if ($.isFunction(settings)) {
+ settings = {load: settings};
+ }
- settings = settings || {};
+ settings = settings || {};
- return new track($element.get(0), this.media, $.extend({}, this.settings[kind], settings));
- }
- }
+ return new track($element.get(0), this, settings);
+ });
})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.