(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 */ /* global console, document, navigator, soundManager, window */ '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; /** * The following are player object event callback examples. * Override globally by setting window.sm2BarPlayers.on = {}, or individually by window.sm2BarPlayers[0].on = {} etc. * soundObject is provided for whileplaying() etc., but playback control should be done via the player object. */ players.on = { /* play: function(player, soundObject) { console.log('playing', player); }, whileplaying: function(player, soundObject) { console.log('whileplaying', player, soundObject); }, finish: function(player, soundObject) { // each sound console.log('finish', player); }, pause: function(player, soundObject) { console.log('pause', player); }, error: function(player, soundObject) { console.log('error', player); }, end: function(player, soundObject) { // 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 < j; i++) { players.push(new Player(nodes[i])); } } }); /** * player bits */ Player = function (playerNode) { var css, dom, extras, playlistController, soundObject, actions, actionData, defaultItem, defaultVolume, firstOpen, exports; css = { disabled: 'disabled', selected: 'selected', active: 'active', legacy: 'legacy', noVolume: 'no-volume', playlistOpen: 'playlist-open' }; dom = { o: null, playlist: null, playlistTarget: null, playlistContainer: null, time: null, player: null, progress: null, progressTrack: null, progressBar: null, duration: null, volume: null }; // prepended to tracks when a sound fails to load/play extras = { loadFailedCharacter: '✖' }; function stopOtherSounds() { if (playerOptions.stopOtherSounds) { soundManager.stopAll(); } } function callback(method, oSound) { if (method) { // fire callback, passing current player and sound objects if (exports.on && exports.on[method]) { exports.on[method](exports, oSound); } else if (players.on[method]) { players.on[method](exports, oSound); } } } 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