// This file is custom JS for Alligator player, anything not part of jPlayer var urlPrefix = "/"; var imagesAndMP3Prefix = ""; var isJukebox = false; // vs mini player var timeOutInSeconds = 60*60; var isPoppedOut = false; var inAPopUp = false; var didLoaded = false; $(document).ready(function() { isJukebox = ($(document).getUrlParam("jukebox")=="yes"); inAPopUp = ($(document).getUrlParam("inAPopUp")=="yes"); isPoppedOut = ((Cookies.get('miniPlayerIsPopped')=="yes") && ($(document).getUrlParam("inAPopUp")!="yes")) window.myPlaylist = new jPlayerPlaylist({ jPlayer: "#jquery_jplayer_1", cssSelectorAncestor: "#jp_container_1" }, [] , { loop : true, supplied: "mp3", useStateClassSkin: true, autoBlur: false, smoothPlayBar: true, autoPlay:true, playlistOptions: { loopOnPrevious: true, shuffleOnLoop: true, enableRemoveControls: false, displayTime: 0, addTime: 0, removeTime: 0, shuffleTime: 0 } ,play : function (e) { Cookies.set('playerPaused', 'no'); if (inAPopUp) { if (typeof window.opener.pauseAllPreviews === "function") { window.opener.pauseAllPreviews(); } } else { if (typeof pauseAllPreviews === "function") { pauseAllPreviews(); } } } ,pause : function (e) { Cookies.set('playerPaused', 'yes'); } ,loadeddata: function(e) { // console.log("loaded data"); } ,setmedia: function(e) { // console.log("set media"); setAlbumImageAndArtistSongText(myPlaylist.current,myPlaylist); if (Cookies.get('currentTime')!=null) { var action = "play"; if (Cookies.get('playerPaused')=="yes") { action = "pause"; } $("#jquery_jplayer_1").jPlayer(action, Number(Cookies.get('currentTime'))); } } ,ready : function(e) { // console.log("ready"); if (!isJukebox) { addPlaylist(); } } ,timeupdate : handleProgressBar }); // ======== Change look of player based on various settings if (inAPopUp) { $(".pop-out-text").css("display", "none"); $(".artist-text").css("width", "158px"); //pop out button not in pop up so we can show more artist text $( window ).resize(function() { handlePopUpSizing(); }); if (isJukebox) { setTimeout(timeOutJukebox,1000*timeOutInSeconds); } else { $(".playlist-container").css("display", "none"); } handlePopUpSizing(); } else { if (!isJukebox) { $(".playlist-container").css("display", "none"); } } if (isPoppedOut) { $(".jp-type-playlist").css("display", "none"); $(".return-to-mini-player").css("display", "block"); } if (Cookies.get('playerVolume')!=null) { var v = parseFloat(Cookies.get('playerVolume')); $(".jp-jplayer").jPlayer( "volume", v); $("[data-slider]").simpleSlider("setRatio", v); } if ((Cookies.get('isMuted')!=null) && (!inAPopUp)) { if (Cookies.get('isMuted')=="yes") { $(".jp-jplayer").jPlayer( "mute"); } } // ========================== // Button Clicks ============================= $( ".jp-mute" ).click(function() { if (!inAPopUp) if ((Cookies.get("isMuted")==null) || (Cookies.get("isMuted")=="no")) { Cookies.set("isMuted","yes"); } else { Cookies.set("isMuted","no"); } }); $( ".remove-song" ).click(function() { Cookies.remove('currentTime'); setAlbumImageAndArtistSongText(-1,null); myPlaylist.remove(myPlaylist.current); }); $( ".clear-song" ).click(function() { $(".play-bar").css("left", "0%"); Cookies.remove('currentTime'); setAlbumImageAndArtistSongText(-1,null); myPlaylist.remove(); }); $( ".continue-playing-text" ).click(function() { $(".jp-type-playlist").css("display", "block"); $(".continue-playing").css("display", "none"); setTimeout(timeOutJukebox,1000*timeOutInSeconds); }); $( ".return-to-mini-player-text" ).click(function() { isPoppedOut = false; Cookies.set('miniPlayerIsPopped', 'no'); $(".jp-type-playlist").css("display", "block"); $(".return-to-mini-player").css("display", "none"); getPopUp(false).close(); var currentTrackNum = 0; if (Cookies.get('currentTrack')!=null) var currentTrackNum = Number(Cookies.get('currentTrack')); myPlaylist.select(currentTrackNum); $("#jquery_jplayer_1").jPlayer("play", Number(Cookies.get('currentTime')) ); }); $( ".pop-out-text" ).click(function() { Cookies.set('readTimeInPopUp', 'yes'); myPlaylist.pause(); isPoppedOut = true; Cookies.set('miniPlayerIsPopped', 'yes'); popUpPlayer(false); $(".jp-type-playlist").css("display", "none"); $(".return-to-mini-player").css("display", "block"); }); // ============================================ // jPlayer Volume slider stinks, need to make our own $("[data-slider]").bind("slider:ready slider:changed", function (event, data) { $(".jp-jplayer").jPlayer( "volume", data.value.toFixed(3)); Cookies.set('playerVolume', ''+data.value.toFixed(3)); }); // cookie every second to same current time on player setInterval(saveTime,1000); // MOBILE STUFF ==================== if (getMobileOperatingSystem()=="iOS") { $(".jp-current-time").css("left","132px"); //hack $(".pop-out-text").css("display", "none"); } else if (getMobileOperatingSystem()=="Android") { $(".pop-out-text").css("display", "none"); } }); function handleProgressBar() { if (isPoppedOut) { myPlaylist.pause(); // make sure we're paused, other methods at this failed } else { var currentTime = Math.floor($('#jquery_jplayer_1').data().jPlayer.status.currentTime); var percentPlayed = (currentTime / myPlaylist.playlist[myPlaylist.current].duration) * 100; $(".play-bar").css("left", percentPlayed+"%"); } } function handlePopUpSizing() { if (isJukebox) playerHeight = 300 else playerHeight = 66; var wVal = $( window ).width()/236; var hVal = $( window ).height()/playerHeight; var val =1; if ((wVal>1) && (hVal>1)) if (wVal0) { var trackIndex = d.COLUMNS.indexOf("TRACKNAME"); var artistIndex = d.COLUMNS.indexOf("ARTIST"); var albumIndex = d.COLUMNS.indexOf("ALBUMNAME"); var mp3Index = d.COLUMNS.indexOf("TRACKURL"); var albumImageIndex = d.COLUMNS.indexOf("ALBUMIMAGE"); var duration = d.COLUMNS.indexOf("DURATION"); var tempPlaylist = []; for (var i=0; ipl.length) { startTrack = 0; } } else { startTrack = 0; } } myPlaylist.setPlaylist(pl,startTrack); }, error: function(xhr, desc, err) { alert("Details: " + desc + "\nError:" + err); } }); } // Set the artist song and album info above the progress bar, marquee the album and song if too long // Null myPlayList clears everything function setAlbumImageAndArtistSongText(index,myPlaylist) { if (myPlaylist==null) { $(".artist-text" ).text (""); $(".album-song-text" ).text (""); $(".album-box-art").css("background-image", "url('image/blankAlbumCover.png')"); } else { Cookies.set('currentTrack', ''+myPlaylist.current, { expires: 1 }); // days $(".album-box-art").css("background-image", "url('"+myPlaylist.playlist[index].albumImage+"')"); var $mq = $('.album-song-text').marquee(); if ($mq!=null) { $mq.marquee('destroy'); } $( ".artist-text" ).text (myPlaylist.playlist[index].artist); $( ".album-song-text" ).text (myPlaylist.playlist[index].album + " - " + myPlaylist.playlist[index].title); var str = $( ".album-song-text" ).text(); if (str.length>27) { $('.album-song-text').marquee({ duration: 5000, gap: 10, delayBeforeStart: 0, direction: 'left', duplicated: true }); } } } // Called after an hour, if song is playing then show the continue listnening button, if not playing check again in an hour function timeOutJukebox() { var isPaused = $('#jquery_jplayer_1').data().jPlayer.status.paused; if (!isPaused) { $('#jquery_jplayer_1').data().jPlayer.pause(); $(".jp-type-playlist").css("display", "none"); $(".continue-playing").css("display", "block"); } else { setTimeout(timeOutJukebox,1000*timeOutInSeconds); } } // pushes a cookie every second with current time function saveTime() { var currentTime = Math.floor($('#jquery_jplayer_1').data().jPlayer.status.currentTime); Cookies.set('currentTime', ''+currentTime, { expires: 1 }); // days } function getMobileOperatingSystem() { var userAgent = navigator.userAgent || navigator.vendor || window.opera; // Windows Phone must come first because its UA also contains "Android" if (/windows phone/i.test(userAgent)) { return "Windows Phone"; } if (/android/i.test(userAgent)) { return "Android"; } // iOS detection from: http://stackoverflow.com/a/9039885/177710 if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { return "iOS"; } return "unknown"; }