/* * Author: Audio Player with Playlist * Website: http://digitalzoomstudio.net/ * Portfolio: http://bit.ly/nM4R6u * Version: 2.54 * */ function htmlEncode(arg){ return jQuery('
').text(arg).html(); } function htmlDecode(value){ return jQuery('').html(arg).text(); } var dzsap_list = []; var dzsap_ytapiloaded = false; var dzsap_globalidind = 20; (function($) { $.fn.prependOnce = function(arg, argfind) { var _t = $(this) // It's your element // console.info(argfind); if(typeof(argfind) =='undefined'){ var regex = new RegExp('class="(.*?)"'); var auxarr = regex.exec(arg); if(typeof auxarr[1] !='undefined'){ argfind = '.'+auxarr[1]; } } // we compromise chaining for returning the success if(_t.children(argfind).length<1){ _t.prepend(arg); return true; }else{ return false; } }; $.fn.appendOnce = function(arg, argfind) { var _t = $(this) // It's your element if(typeof(argfind) =='undefined'){ var regex = new RegExp('class="(.*?)"'); var auxarr = regex.exec(arg); if(typeof auxarr[1] !='undefined'){ argfind = '.'+auxarr[1]; } } // we compromise chaining for returning the success if(_t.children(argfind).length<1){ _t.append(arg); return true; }else{ return false; } }; $.fn.audioplayer = function(o) { var defaults = { design_skin: 'skin-default' ,autoplay: 'off' ,cue: 'on' ,swf_location: "ap.swf"//==the location of the flash backup ,swffull_location: "apfull.swf"//==the location of the flash backup ,settings_backup_type: 'light' // == light or full ,settings_extrahtml: '' // == some extra html - can be rates, plays, likes ,settings_trigger_resize : '0' ,design_thumbh: "default"//thumbnail size ,design_thumbw: "200" ,disable_volume: 'default' ,disable_scrub: 'default' ,disable_player_navigation: 'off' ,disable_timer: 'default' ,type: 'audio' ,embed_code: '' ,skinwave_dynamicwaves: 'off' // ===dynamic scale based on volume for no spectrum wave ,soundcloud_apikey: '' ,parentgallery: undefined ,skinwave_enableSpectrum: 'off' // off or on ,skinwave_enableReflect: 'on' ,settings_useflashplayer: 'auto' // off or on or auto ,skinwave_spectrummultiplier: '1' // == number ,skinwave_comments_enable: 'off' ,settings_php_handler: 'publisher.php' ,php_retriever: 'soundcloudretriever.php' ,skinwave_mode: 'normal' // --- "normal" or "small" ,skinwave_comments_playerid: '' ,skinwave_comments_account: 'none' ,skinwave_comments_retrievefromajax: 'off'// --- retrieve the comment form ajax ,skinwave_comments_displayontime: 'on'// --- display the comment when the scrub header is over it ,skinwave_timer_static: 'off' ,skinwave_comments_avatar: 'http://www.gravatar.com/avatar/00000000000000000000000000000000?s=20'//==default image ,skinwave_spectrum_wavesbg: '4f4949' // == number ,skinwave_spectrum_wavesprog: 'ae1919' // == number ,design_menu_show_player_state_button: 'off' ,playfrom: 'off' //off or specific number of settings or set to "last" ,design_animateplaypause: 'default' ,embedded: 'off' ,sample_time_start: '0' // --- if this is a sample to a complete song, you can write here start times, if not, leave to 0. ,sample_time_end: '0' ,sample_time_total: '0' ,google_analytics_send_play_event: 'off' } o = $.extend(defaults, o); if(typeof o =='undefined'){ if(typeof $(this).attr('data-options')!='undefined' && $(this).attr('data-options')!=''){ var aux = $(this).attr('data-options'); aux = 'var aux_opts = ' + aux; eval(aux); o = aux_opts; } } this.each(function() { var cthis = $(this); var cchildren = cthis.children() ,cthisId = 'ap1' ; var currNr = -1; var busy = true; var i = 0; var ww , wh , tw , th ,cw //controls width ,ch //controls height ,sw = 0//scrubbar width ,sh ,spos = 0 //== scrubbar prog pos ; var _audioplayerInner ,_apControls = null ,_apControlsLeft = null ,_apControlsRight = null ,_conControls ,_conPlayPause ,_controlsVolume ,_scrubbar ,_theMedia ,_cmedia ,_theThumbCon ,_metaArtistCon ,_scrubBgReflect = null ,_scrubBgReflectCanvas = null ,_scrubBgReflectCtx = null ,_scrubProgReflect = null ,_scrubProgCanvasReflect = null ,_scrubProgCanvasReflectCtx = null ,_scrubBgCanvas = null ,_scrubBgCanvasCtx = null ,_scrubProgCanvas = null ,_scrubProgCanvasCtx = null ,_commentsHolder = null ,_commentsWriter = null ,_currTime = null ,_totalTime = null ; var busy = false ,playing = false ,muted = false ,loaded=false ,destroyed = false ,google_analytics_sent_play_event = false ; var time_total = 0 ,time_curr=0 ,real_time_curr=0 ,real_time_total = 0 ,sample_time_start=0 ,sample_time_end=0 ,sample_time_total=0 ,sample_perc_start=0 ,sample_perc_end=0 ; var index_extrahtml_toloads = 0; var last_vol = 1 ,last_vol_before_mute = 1 ,the_player_id = '' ; var inter_check ,inter_checkReady ,inter_audiobuffer_workaround_id = 0 ,inter_trigger_resize ; var skin_minimal_canvasplay ,skin_minimal_canvaspause ; var is_flashplayer = false ; var data_source ; var res_thumbh = false; // resize thumb height var str_ie8 = ''; //===spectrum stuff var javascriptNode = null; var audioCtx = null; var audioBuffer = null; var sourceNode = null; var analyser = null; var lastarray = null; var webaudiosource = null; var canw = 100; var canh = 100; var barh = 100 ,design_thumbh ; var type = ''; var sposarg = 0; // the % at which the comment will be placed var arr_the_comments = []; var lasttime_inseconds = 0; var controls_left_pos = 0; var controls_right_pos = 0; var ajax_view_submitted = 'auto' ,increment_views = 0 ; var starrating_index = 0 ,starrating_nrrates = 0 ,starrating_alreadyrated = -1 ; var playfrom = 'off' ,playfrom_ready = false ; var currIp = '127.0.0.1'; if(isNaN(parseInt(o.design_thumbh, 10))==false){ o.design_thumbh = parseInt(o.design_thumbh, 10); } if(String(o.design_thumbw).indexOf('%')==-1){ o.design_thumbw = parseInt(o.design_thumbw, 10); } if(Number(o.sample_time_start)>0){ sample_time_start = Number(o.sample_time_start); if(Number(o.sample_time_end)>0){ sample_time_end = Number(o.sample_time_end); if(Number(o.sample_time_total)>0){ sample_time_total = Number(o.sample_time_total); sample_perc_start = sample_time_start/ sample_time_total; sample_perc_end = sample_time_end/ sample_time_total; } } } //console.info(sample_perc_start,sample_perc_end); o.settings_trigger_resize = parseInt(o.settings_trigger_resize, 10); if(cthis.children('.extra-html').length>0 && o.settings_extrahtml==''){ o.settings_extrahtml = cthis.children('.extra-html').eq(0).html(); var re_ratesubmitted = /{{ratesubmitted=(.?)}}/g; if(re_ratesubmitted.test(String(o.settings_extrahtml))){ re_ratesubmitted.lastIndex = 0; var auxa = (re_ratesubmitted.exec(String(o.settings_extrahtml))); starrating_alreadyrated = auxa[1]; o.settings_extrahtml = String(o.settings_extrahtml).replace(re_ratesubmitted, ''); if(o.parentgallery!=undefined && $(o.parentgallery).get(0)!=undefined && $(o.parentgallery).get(0).api_player_rateSubmitted!=undefined){ $(o.parentgallery).get(0).api_player_rateSubmitted(); } } cthis.children('.extra-html').remove(); } init(); function init(){ //console.log(typeof(o.parentgallery)=='undefined'); if(o.design_skin==''){ o.design_skin = 'skin-default'; } if(cthis.attr('class').indexOf("skin-")==-1){ cthis.addClass(o.design_skin); } if(cthis.hasClass('skin-default')){ o.design_skin = 'skin-default'; } if(cthis.hasClass('skin-wave')){ o.design_skin = 'skin-wave'; } if(cthis.hasClass('skin-justthumbandbutton')){ o.design_skin = 'skin-justthumbandbutton'; } if(cthis.hasClass('skin-pro')){ o.design_skin = 'skin-pro'; } if(cthis.hasClass('skin-aria')){ o.design_skin = 'skin-aria'; } if(cthis.attr('data-viewsubmitted')=='on'){ ajax_view_submitted='on'; } if(cthis.attr('data-userstarrating')){ starrating_alreadyrated=Number(cthis.attr('data-userstarrating')); } // console.info(starrating_alreadyrated); if(cthis.hasClass('skin-minimal')){ o.design_skin = 'skin-minimal'; if(o.disable_volume=='default'){ o.disable_volume='on'; } if(o.disable_scrub=='default'){ o.disable_scrub='on'; } o.disable_timer='on'; } if(cthis.hasClass('skin-minion')){ o.design_skin = 'skin-minion'; if(o.disable_volume=='default'){ o.disable_volume='on'; } if(o.disable_scrub=='default'){ o.disable_scrub='on'; } o.disable_timer='on'; } if(o.design_skin=='skin-default'){ if(o.design_thumbh=='default'){ design_thumbh = cthis.height() - 40; res_thumbh = true; } } if(o.design_skin=='skin-wave'){ cthis.addClass('skin-wave-mode-'+ o.skinwave_mode); if(o.skinwave_mode == 'small'){ if(o.design_thumbh=='default'){ design_thumbh= 80; } } } if(o.design_skin=='skin-justthumbandbutton'){ if(o.design_thumbh=='default'){ o.design_thumbh = ''; // res_thumbh = true; } o.disable_timer='on'; o.disable_volume='on'; if(o.design_animateplaypause=='default'){ o.design_animateplaypause = 'on'; } } if(o.design_thumbh=='default'){ design_thumbh= 200; } if(o.embed_code==''){ if(cthis.find('div.feed-embed-code').length>0){ o.embed_code = cthis.find('div.feed-embed-code').eq(0).html(); } } if(o.design_animateplaypause=='default'){ o.design_animateplaypause = 'off'; } // console.info(the_player_id, o.skinwave_comments_enable, o.skinwave_comments_playerid); if(o.skinwave_comments_playerid==''){ if(typeof(cthis.attr('id'))!='undefined'){ the_player_id = cthis.attr('id'); } }else{ the_player_id = o.skinwave_comments_playerid; } if(the_player_id==''){ o.skinwave_comments_enable='off'; } playfrom = o.playfrom; if(isValid(cthis.attr('data-playfrom'))){ playfrom = cthis.attr('data-playfrom'); } if(isNaN(parseInt(playfrom,10))==false){ playfrom = parseInt(playfrom,10); } // console.info(the_player_id, o.skinwave_comments_enable); if(cthis.attr('data-type')=='youtube'){ o.type='youtube'; type='youtube'; } if(cthis.attr('data-type')=='soundcloud'){ o.type='soundcloud'; type = 'soundcloud'; } if(cthis.attr('data-type')=='shoutcast'){ o.type='shoutcast'; type = 'audio'; o.disable_timer='on'; //===might still use it for skin-wave if(o.design_skin=='skin-default'){ o.disable_scrub='on'; } // o.disable_scrub = 'on'; } if(type==''){ type='audio'; } //====we disable the function if audioplayer inited if(cthis.hasClass('audioplayer')){ return; } if(cthis.attr('id')!=undefined){ cthisId = cthis.attr('id'); }else{ cthisId = 'ap' + dzsap_globalidind++; } if(is_ie8()){ if(o.cue=='off'){ o.cue='on'; } } cthis.removeClass('audioplayer-tobe'); cthis.addClass('audioplayer'); if(cthis.find('.the-comments').length>0 && cthis.find('.the-comments').eq(0).children().length>0){ arr_the_comments = cthis.find('.the-comments').eq(0).children(); }else{ if(o.skinwave_comments_retrievefromajax=='on'){ var data = { action: 'dzsap_get_comments', postdata: '1', playerid: the_player_id }; // console.info(data); $.ajax({ type: "POST", url: o.settings_php_handler, data: data, success: function(response) { if(typeof window.console != "undefined" ){ console.log('Ajax - get - comments - ' + response); } cthis.prependOnce('', '.the-comments'); if(response.indexOf('a-comment')>-1){ response = response.replace(/a-comment/g, 'a-comment dzstooltip-con'); response = response.replace(/dzstooltip arrow-bottom/g, 'dzstooltip arrow-from-start transition-slidein arrow-bottom'); } cthis.find('.the-comments').eq(0).html(response); arr_the_comments = cthis.find('.the-comments').eq(0).children(); setup_controls_commentsHolder(); }, error:function(arg){ if(typeof window.console != "undefined" ){ console.log('Got this from the server: ' + arg, arg); }; } }); } } //===ios does not support volume controls so just let it die //====== .. or autoplay FORCE STAFF if(is_ios()){ o.disable_volume='on'; o.autoplay = 'off'; } if(is_android()){ o.autoplay = 'off'; } if(type=='youtube'){ if(dzsap_ytapiloaded==false){ var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); dzsap_ytapiloaded = true; } } data_source = cthis.attr('data-source'); //====sound cloud INTEGRATION // if(cthis.attr('data-source')!=undefined && String(cthis.attr('data-source')).indexOf('https://soundcloud.com/')>-1){ type='soundcloud'; } //console.info(o.type); if(type=='soundcloud'){ if(o.soundcloud_apikey==''){ alert('soundcloud api key not defined, read docs!'); } var aux = 'http://api.' + 'soundcloud.com' + '/resolve?url='+data_source+'&format=json&consumer_key=' + o.soundcloud_apikey; //console.info(aux); if( (o.design_skin=='skin-wave' && !cthis.attr('data-scrubbg')) || is_ie8()){ o.skinwave_enableReflect='off'; } aux = encodeURIComponent(aux); $.getJSON((o.php_retriever+'?scurl='+aux), function(data) { //console.log(data, data.waveform_url); type='audio'; if(o.design_skin=='skin-wave' && cthis.attr('data-scrubbg')==undefined){ cthis.attr('data-scrubbg', data.waveform_url); cthis.attr('data-scrubprog', data.waveform_url); _scrubbar.find('.scrub-bg').eq(0).append(''); _scrubbar.find('.scrub-bg').eq(0).append('