| [5] | 1 | var AudioPlayer = function () { |
|---|
| 2 | var instances = []; |
|---|
| 3 | var activeInstanceID; |
|---|
| 4 | var playerURL = ""; |
|---|
| 5 | var defaultOptions = {}; |
|---|
| 6 | var currentVolume = -1; |
|---|
| 7 | |
|---|
| 8 | var getMovie = function (name) { |
|---|
| 9 | return document.all ? window[name] : document[name]; |
|---|
| 10 | }; |
|---|
| 11 | |
|---|
| 12 | return { |
|---|
| 13 | setup: function (url, options) { |
|---|
| 14 | playerURL = url; |
|---|
| 15 | defaultOptions = options; |
|---|
| 16 | }, |
|---|
| 17 | |
|---|
| 18 | embed: function (elementID, options) { |
|---|
| 19 | var instanceOptions = {}; |
|---|
| 20 | var key; |
|---|
| 21 | var so; |
|---|
| 22 | var bgcolor; |
|---|
| 23 | var wmode; |
|---|
| 24 | |
|---|
| 25 | var flashParams = {}; |
|---|
| 26 | var flashVars = {}; |
|---|
| 27 | var flashAttributes = {}; |
|---|
| 28 | |
|---|
| 29 | // Merge default options and instance options |
|---|
| 30 | for (key in defaultOptions) { |
|---|
| 31 | instanceOptions[key] = defaultOptions[key]; |
|---|
| 32 | } |
|---|
| 33 | for (key in options) { |
|---|
| 34 | instanceOptions[key] = options[key]; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | if (instanceOptions.transparentpagebg == "yes") { |
|---|
| 38 | flashParams.bgcolor = "#FFFFFF"; |
|---|
| 39 | flashParams.wmode = "transparent"; |
|---|
| 40 | } else { |
|---|
| 41 | if (instanceOptions.pagebg) { |
|---|
| 42 | flashParams.bgcolor = "#" + instanceOptions.pagebg; |
|---|
| 43 | } |
|---|
| 44 | flashParams.wmode = "opaque"; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | flashParams.menu = "false"; |
|---|
| 48 | |
|---|
| 49 | for (key in instanceOptions) { |
|---|
| 50 | if (key == "pagebg" || key == "width" || key == "transparentpagebg") { |
|---|
| 51 | continue; |
|---|
| 52 | } |
|---|
| 53 | flashVars[key] = instanceOptions[key]; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | flashAttributes.name = elementID; |
|---|
| 57 | flashAttributes.style = "outline: none"; |
|---|
| 58 | |
|---|
| 59 | flashVars.playerID = elementID; |
|---|
| 60 | |
|---|
| 61 | swfobject.embedSWF(playerURL, elementID, instanceOptions.width.toString(), "24", "8.0.0", false, flashVars, flashParams, flashAttributes); |
|---|
| 62 | |
|---|
| 63 | instances.push(elementID); |
|---|
| 64 | }, |
|---|
| 65 | |
|---|
| 66 | syncVolumes: function (playerID, volume) { |
|---|
| 67 | currentVolume = volume; |
|---|
| 68 | for (var i = 0; i < instances.length; i++) { |
|---|
| 69 | if (instances[i] != playerID) { |
|---|
| 70 | getMovie(instances[i]).setVolume(currentVolume); |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | }, |
|---|
| 74 | |
|---|
| 75 | activate: function (playerID) { |
|---|
| 76 | if (activeInstanceID && activeInstanceID != playerID) { |
|---|
| 77 | getMovie(activeInstanceID).closePlayer(); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | activeInstanceID = playerID; |
|---|
| 81 | }, |
|---|
| 82 | |
|---|
| 83 | getVolume: function (playerID) { |
|---|
| 84 | return currentVolume; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | }(); |
|---|