// Namespace var mejs = mejs || {}, codepeople_avp_generator = function() { if('undefined' != typeof codepeople_avp_generator_flag) return; codepeople_avp_generator_flag = true; var $ = jQuery; if(parseInt($.fn.jquery.replace(/\./g, '')) < 183) { $.ajax( { url: 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', dataType: "script", success: function(data) { codepeople_avp(jQuery.noConflict()); } } ); } else codepeople_avp($); }; function codepeople_avp($){ var jQuery = $; /*** PLAYLIST CONTROLS ***/ mejs.Playlist = function(player){ var me = this, c = player.container, n = player.$node, id = (n.closest('mediaelementwrapper').length) ? n.closest('mediaelementwrapper').attr('id') : n.attr('id'), clss = n.attr('class').split(/\s+/), playlist = $('[id="'+id+'-list"]'); // The playlist loop was activated me.loop = (n.attr('loop')) ? true : false; n.removeAttr('loop'); // Player size me.playerWidth = c.width(); me.playerHeight = c.height(); // Set the player object associated to the playlist me.player = player; // Set the player id me.playerId = id; // Playback the next playlist item me.player.media.addEventListener('ended', function (e) { me.player.pause(); if(me.playlist && 2<=me.playlist.find('li').length) me.playNext(); else if(me.loop){ me.player.play(); } }, false); // There is a playlist associated to the player if(playlist.length){ // Set the playlist node me.playlist = playlist; // Set the playlist class me.playlist.addClass('emjs-playlist'); // Set the skin class to playlist for(var i = 0, h = clss.length; i < h; i++){ if(/\-skin/i.test(clss[i])){ me.skin = clss[i]; me.playlist.addClass(me.skin); break; } } // Set the playlist width me.playlist.width(c.width()); // Associate click events to the playlist items $('li', me.playlist).click(function(){me.selectItem($(this));}); // Associate the playist to the music player me.player.playlist = me; } }; mejs.Playlist.prototype = { playlist : null, player : null, playerId : '', playerWidth : null, playerHeight : null, attributes :{ show : true }, skin : null, parseItem : function(item){ var e; try{ return $.parseJSON(item); }catch(e){ return item; } }, parseSrc : function(src){ function adjustedSrc(v){ var d = new Date(); v += ((v.indexOf('?') == -1) ? '?' : '&cpmp=')+d.getTime(); return v; }; var source = {}; if(typeof src != 'string'){ // The src is an object if(src.type) source['type'] = src.type; if(src.src) source['src'] = adjustedSrc(src.src); }else { // The src is a string with media location source['src'] = adjustedSrc(src); } return source; }, parseTrack : function(trck){ var track = '' + '' + '') // append it to the toolbar .appendTo(controls) // add a click toggle event .click(function() { if(player.playlist) player.playlist.playNext(); }); }; /*** PREVIOUS BUTTON CONTROL ***/ MediaElementPlayer.prototype.buildprevious = function(player, controls, layers, media) { if(jQuery('[id="'+media.id+'-list"] li').length < 2) return; var // create the loop button next = $('
' + '' + '
') // append it to the toolbar .appendTo(controls) // add a click toggle event .click(function() { if(player.playlist) player.playlist.playNext(false); }); }; /*** EQ CONTROL ***/ MediaElementPlayer.prototype.buildeq = function(player, controls, layers, media) { var // create the eq bars eq = $('') // append it to the toolbar .appendTo(controls); // Animate bars function fluctuate(bar, h) { var v = player.media.volume || 0, hgt = (Math.random()) * h * v, t = (hgt+1) * 30; if(media.paused || media.ended) { eq.hide(); }else if(media.currentTime){ eq.show(); } bar.animate({ height: hgt }, t, function() { fluctuate($(this), h); }); } controls.find('.bar').each(function(i, bar){ var b = $(bar), w = b.width(), h = b.height(); b.css('left', (w*i+2*i)+'px'); fluctuate(b, h); }); }; $('.codepeople-media').each(function(){ var me = $(this), settings = { features: ['previous','playpause','next','fullscreen','tracks','eq','current','progress','duration','volume'], videoVolume: 'horizontal', iPadUseNativeControls: false, iPhoneUseNativeControls: false, success: function(media, node, player) { var cp = $(node).parents('.codepeople-media'); if(media.pluginType && media.pluginType == 'silverlight'){ cp.addClass('silverlight'); } // Set titles cp.find( '.mejs-time-handle' ).attr( 'title', 'Seek' ); cp.find( '.mejs-horizontal-volume-current,.mejs-vertical-volume-current' ).attr( 'title', 'Volume' ); // Get skin var cls = cp.attr('class'); cls = cls.replace(/^\s+/, '').replace(/\s+$/, ''); cls = cls.split(/\s+/); for(var i = 0, h = cls.length; i < h; i++){ if(/\-skin$/.test(cls[i])){ if( typeof cp_skin_js != 'undefined' && cp_skin_js[cls[i]]){ cp_skin_js[cls[i]]($); } break; } } media.addEventListener( 'play', function(){ var p = $( node ).parents( '#ms_avp' ); if( p.length && p.find( '.current' ).length == 0 ){ p.find( '.emjs-playlist li:first' ).addClass( 'current' ); } } ); new mejs.Playlist(player); } }; settings[ 'defaultVideoHeight' ] = settings[ 'audioHeight' ] = settings[ 'videoHeight' ] = me.height(); settings[ 'defaultVideoWidth' ] = settings[ 'audioWidth' ] = settings[ 'videoWidth' ] = me.parent('#ms_avp').width(); me.mediaelementplayer( settings ); }); } jQuery(codepeople_avp_generator); jQuery(window).on('load',codepeople_avp_generator);