/*jslint plusplus: true, white: true, nomen: true */
/*global console, document, navigator, soundManager, window */
(function(window) {
/**
* SoundManager 2: "Bar UI" player
* Copyright (c) 2014, Scott Schiller. All rights reserved.
* http://www.schillmania.com/projects/soundmanager2/
* Code provided under BSD license.
* http://schillmania.com/projects/soundmanager2/license.txt
*/
"use strict";
var Player,
players = [],
// CSS selector that will get us the top-level DOM node for the player UI.
playerSelector = '.sm2-bar-ui',
playerOptions,
utils;
/**
* Slightly hackish: event callbacks.
* Override globally by setting window.sm2BarPlayers.on = {}, or individually by window.sm2BarPlayers[0].on = {} etc.
*/
players.on = {
/*
play: function(player) {
console.log('playing', player);
},
finish: function(player) {
// each sound
console.log('finish', player);
},
pause: function(player) {
console.log('pause', player);
},
error: function(player) {
console.log('error', player);
}
end: function(player) {
// end of playlist
console.log('end', player);
}
*/
};
playerOptions = {
// useful when multiple players are in use, or other SM2 sounds are active etc.
stopOtherSounds: true,
// CSS class to let the browser load the URL directly e.g., download foo.mp3
excludeClass: 'sm2-exclude'
};
soundManager.setup({
// trade-off: higher UI responsiveness (play/progress bar), but may use more CPU.
html5PollingInterval: 50,
flashVersion: 9
});
soundManager.onready(function() {
var nodes, i, j;
nodes = utils.dom.getAll(playerSelector);
if (nodes && nodes.length) {
for (i=0, j=nodes.length; i✖'
};
function stopOtherSounds() {
if (playerOptions.stopOtherSounds) {
soundManager.stopAll();
}
}
function callback(method) {
if (method) {
// fire callback, passing current turntable object
if (exports.on && exports.on[method]) {
exports.on[method](exports);
} else if (players.on[method]) {
players.on[method](exports);
}
}
}
function getTime(msec, useString) {
// convert milliseconds to hh:mm:ss, return as object literal or string
var nSec = Math.floor(msec/1000),
hh = Math.floor(nSec/3600),
min = Math.floor(nSec/60) - Math.floor(hh * 60),
sec = Math.floor(nSec -(hh*3600) -(min*60));
// if (min === 0 && sec === 0) return null; // return 0:00 as null
return (useString ? ((hh ? hh + ':' : '') + (hh && min < 10 ? '0' + min : min) + ':' + ( sec < 10 ? '0' + sec : sec ) ) : { 'min': min, 'sec': sec });
}
function setTitle(item) {
// given a link, update the "now playing" UI.
// if this is an with an inner link, grab and use the text from that.
var links = item.getElementsByTagName('a');
if (links.length) {
item = links[0];
}
// remove any failed character sequence, also
dom.playlistTarget.innerHTML = '- ' + item.innerHTML.replace(extras.loadFailedCharacter, '') + '
';
if (dom.playlistTarget.getElementsByTagName('li')[0].scrollWidth > dom.playlistTarget.offsetWidth) {
// this item can use