/** * jquery.cxassette.js v1.0.0 * http://www.codrops.com * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Copyright 2012, Codrops * http://www.codrops.com */ ( function( window, $, undefined ) { var aux = { getSupportedType : function() { var audio = document.createElement( 'audio' ); if ( audio.canPlayType('audio/mpeg;') ) { return 'mp3'; } else if ( audio.canPlayType('audio/ogg;') ) { return 'ogg'; } else { return 'wav'; } } }; // Cassette obj $.Cassette = function( options, element ) { this.$el = $( element ); this._init( options ); }; $.Cassette.defaults = { // song names. Assumes the path of each song is songs/name.filetype songs : [ 'BlueDucks_FourFlossFiveSix', 'BlankKytt_ThursdaySnowReprise', 'BlueDucks_FlossSuffersFromGammaRadiation', 'BlankKyt_RSPN' ], fallbackMessage : 'HTML5 audio not supported', // initial sound volume initialVolume : 0.7 }; $.Cassette.prototype = { _init : function( options ) { var _self = this; // the options this.options = $.extend( true, {}, $.Cassette.defaults, options ); // current side of the tape this.currentSide = 1; // current time of playing side this.cntTime = 0; // current sum of the duration of played songs this.timeIterator = 0; // used for rewind / forward this.elapsed = 0.0; // action performed this.lastaction = ''; // if play / forward / rewind active.. this.isMoving = false; this.$loader = this.$el.find( 'div.vc-loader' ).show(); // create cassette sides $.when( this._createSides() ).done( function() { _self.$loader.hide(); // create player _self._createPlayer(); _self.sound = new $.Sound(); // load events _self._loadEvents(); } ); }, _getSide : function() { return ( this.currentSide === 1 ) ? { current : this.side1, reverse : this.side2 } : { current : this.side2, reverse : this.side1 }; }, // songs are distributed equally on both sides _createSides : function() { var playlistSide1 = [], playlistSide2 = [], _self = this, cnt = 0; return $.Deferred( function( dfd ) { for( var i = 0, len = _self.options.songs.length; i < len; ++i ) { var song = new $.Song( _self.options.songs[i], i ); $.when( song.loadMetadata() ).done( function( song ) { ( song.id < len / 2 ) ? playlistSide1.push( song ) : playlistSide2.push( song ); ++cnt; if( cnt === len ) { // two sides, each side with multiple songs _self.side1 = new $.Side( 'side1', playlistSide1, 'start' ), _self.side2 = new $.Side( 'side2', playlistSide2, 'end' ); dfd.resolve(); } } ); } } ).promise(); }, _createPlayer : function() { // create HTML5 audio element this.$audioEl = $( '' ); this.$el.prepend( this.$audioEl ); this.audio = this.$audioEl.get(0); // create custom controls this._createControls(); this.$theTape = this.$el.find( 'div.vc-tape' ); this.$wheelLeft = this.$theTape.find( 'div.vc-tape-wheel-left' ); this.$wheelRight= this.$theTape.find( 'div.vc-tape-wheel-right' ); this.$tapeSideA = this.$theTape.find( 'div.vc-tape-side-a' ).show(); this.$tapeSideB = this.$theTape.find( 'div.vc-tape-side-b' ); }, _createControls : function() { var _self = this; this.$controls = $( '