Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | reyssat | 1 | /* |
2 | FlashSound javascript class for sonifying web pages with flash player |
||
3 | copyright 2001 Hayden Porter, hayden@aviarts.com |
||
4 | |||
5 | Modified by Raymond Irving 27-Jan-2003 |
||
6 | This port of the FlashSound API (v1.8) will only work with DynAPI 2.9+ |
||
7 | |||
8 | For more information please see the FlashSound Quick Reference |
||
9 | |||
10 | */ |
||
11 | |||
12 | function FlashSound(swfURL,loop,autostart){ |
||
13 | |||
14 | this.DynLayer = DynLayer; |
||
15 | this.DynLayer(null,-10,-10,1,1); |
||
16 | |||
17 | // add layer to document |
||
18 | dynapi.document.addChild(this); |
||
19 | |||
20 | // instance properties |
||
21 | this.playerID = this.id + "SWF"; |
||
22 | FlashSound.players[FlashSound.players.length] = this; |
||
23 | |||
24 | // instance embed properties |
||
25 | this.autostart = true; |
||
26 | this.base = null; |
||
27 | this.bgcolor = null; |
||
28 | this.loop = (loop)? loop:false; |
||
29 | this.src = null; |
||
30 | |||
31 | // setup flash plugin |
||
32 | this.setSWF(swfURL); |
||
33 | |||
34 | }; |
||
35 | |||
36 | |||
37 | /* ============== FlashSound Instance methods =============== */ |
||
38 | |||
39 | /* |
||
40 | javascript embed --------------------------------- |
||
41 | embeds swf if user has a supported browser and minimum player. |
||
42 | script sets swf bgcolor attribute to document.bgcolor if no custom color specified. |
||
43 | */ |
||
44 | var p = dynapi.setPrototype('FlashSound','DynLayer'); |
||
45 | |||
46 | p._recognizeMethod = function (objstr){ |
||
47 | // check for player readiness ---------------------- |
||
48 | // check for javascript DOM object first then check to see if any frames are loaded in maintimeline |
||
49 | if(typeof(this.doc[this.playerID][objstr]) == "undefined") return false; |
||
50 | else return true; |
||
51 | }; |
||
52 | |||
53 | p._checkForInstance = function() { |
||
54 | if(!FlashSound.supportedBrowser || !FlashSound.checkForMinPlayer()) return false; |
||
55 | if (this.doc[this.playerID] == null) return false; |
||
56 | return true; |
||
57 | }; |
||
58 | |||
59 | // Public Methods ------------------- |
||
60 | |||
61 | p.isPlayerReady = function(){ |
||
62 | if(!FlashSound.engage) return false; |
||
63 | if(!this._checkForInstance()) return false; |
||
64 | // block browsers that do not recognize Flash javascript methods |
||
65 | if(!this._recognizeMethod("PercentLoaded")) return false; |
||
66 | if(this.percentLoaded() > 0) return true; |
||
67 | return false; |
||
68 | }; |
||
69 | |||
70 | p.getFramesLoaded = function(target){ |
||
71 | if(!this._checkForInstance()) {return 0;} |
||
72 | if(target == null) target = "/"; |
||
73 | var framesloaded = this.doc[this.playerID].TGetProperty(target,12); |
||
74 | return parseInt(framesloaded); |
||
75 | }; |
||
76 | |||
77 | p.getTotalFrames = function(target){ |
||
78 | if(!this.isPlayerReady()) {return 0;} |
||
79 | if(target == null) target = "/"; |
||
80 | var totalframes = this.doc[this.playerID].TGetProperty(target,5); |
||
81 | return parseInt(totalframes); |
||
82 | }; |
||
83 | |||
84 | // check to see if all frames are loaded for a given timeline. |
||
85 | // check before moving playhead to a frame/label incase the frame/label is not yet loaded. |
||
86 | p.isLoaded = function(target){ |
||
87 | if(!this.isPlayerReady()) return false; |
||
88 | if(target == null) target = "/"; |
||
89 | if (this.getFramesLoaded(target) == this.getTotalFrames(target)) return true; |
||
90 | return false; |
||
91 | }; |
||
92 | |||
93 | /* flash javascript api functions ------------------------ */ |
||
94 | |||
95 | p.gotoAndPlay = function(target,frame){ |
||
96 | if(!this.isPlayerReady()) return; |
||
97 | if(typeof(frame) == "number") { |
||
98 | this.doc[this.playerID].TGotoFrame(target,frame - 1); |
||
99 | this.doc[this.playerID].TPlay(target); |
||
100 | } |
||
101 | if(typeof(frame) == "string") { |
||
102 | this.doc[this.playerID].TGotoLabel(target,frame); |
||
103 | this.doc[this.playerID].TPlay(target); |
||
104 | } |
||
105 | }; |
||
106 | |||
107 | p.gotoAndStop = function(target,frame){ |
||
108 | if(!this.isPlayerReady()) return; |
||
109 | if(typeof(frame) == "number") { |
||
110 | this.doc[this.playerID].TGotoFrame(target,frame - 1); |
||
111 | } |
||
112 | if(typeof(frame) == "string") { |
||
113 | this.doc[this.playerID].TGotoLabel(target,frame); |
||
114 | } |
||
115 | }; |
||
116 | |||
117 | // Is Playing (IsPlaying) |
||
118 | p.isPlaying = function(){ |
||
119 | if(!this.isPlayerReady()) return false; |
||
120 | return this.doc[this.playerID].IsPlaying(); |
||
121 | }; |
||
122 | |||
123 | // Load Movie |
||
124 | p.loadMovie = function(layerNumber,url){ |
||
125 | if(!this.isPlayerReady()) return; |
||
126 | this.doc[this.playerID].LoadMovie(layerNumber,url); |
||
127 | }; |
||
128 | |||
129 | p.percentLoaded = function(){ |
||
130 | if(!this._checkForInstance()) return 0; |
||
131 | var percentLoaded = this.doc[this.playerID].PercentLoaded(); |
||
132 | return parseInt(percentLoaded); |
||
133 | }; |
||
134 | |||
135 | p.play = function(target){ |
||
136 | if(!this.isPlayerReady()) return; |
||
137 | if(target == null) target = "/"; |
||
138 | this.doc[this.playerID].TPlay(target); |
||
139 | }; |
||
140 | |||
141 | // Set SWF |
||
142 | p.setSWF = function(swfURL){ |
||
143 | if (!FlashSound.supportedBrowser || !FlashSound.checkForMinPlayer()) return; |
||
144 | |||
145 | var defaultColor = (document.bgColor != null) ? document.bgColor : "#ffffff"; |
||
146 | var defaultBase = "."; |
||
147 | swfURL=(swfURL)? swfURL:''; |
||
148 | this.bgcolor = (this.bgcolor == null) ? defaultColor : this.bgcolor; |
||
149 | this.base = (this.base == null) ? defaultBase : this.base; |
||
150 | this.src = (swfURL.charAt(0) == "/") ? "http://" + location.host+swfURL : swfURL; |
||
151 | this.setHTML( |
||
152 | '<OBJECT' + '\n' + |
||
153 | 'classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"' + '\n' + |
||
154 | 'codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab\"' + '\n' + |
||
155 | 'WIDTH=1' + '\n' + |
||
156 | 'HEIGHT=1' + '\n' + |
||
157 | 'ID=\"' + this.playerID + '\">' + '\n' + |
||
158 | '<PARAM NAME=movie VALUE=\"' + this.src + '\">' + '\n' + |
||
159 | '<PARAM NAME=play VALUE=\"' + this.autostart + '\">' + '\n' + |
||
160 | '<PARAM NAME=loop VALUE=\"' + this.loop + '\">' + '\n' + |
||
161 | '<PARAM NAME=quality VALUE=low>' + '\n' + |
||
162 | '<PARAM NAME=wmode VALUE=transparent>' + '\n' + |
||
163 | '<PARAM NAME=bgcolor VALUE=' + this.bgcolor + '>' + '\n' + |
||
164 | '<PARAM NAME=base VALUE=\"' + this.base + '\">' + '\n' + |
||
165 | '<EMBED' + '\n' + |
||
166 | 'name=\"' + this.playerID + '\"' + '\n' + |
||
167 | 'swLiveConnect=\"true\"' + '\n' + |
||
168 | 'src=\"' + this.src + '\"' + '\n' + |
||
169 | 'play=\"' + this.autostart + '\"' + '\n' + |
||
170 | 'loop=\"' + this.loop + '\"' + '\n' + |
||
171 | 'quality=low' + '\n' + |
||
172 | 'wmode=transparent' + '\n' + |
||
173 | 'base=\"' + this.base + '\"' + '\n' + |
||
174 | 'bgcolor=' + this.bgcolor + '\n' + |
||
175 | 'WIDTH=1' + '\n' + |
||
176 | 'HEIGHT=2' + '\n' + |
||
177 | 'TYPE=\"application/x-shockwave-flash\"' + '\n' + |
||
178 | 'PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">' + |
||
179 | '\n' + |
||
180 | '</EMBED>' + '\n' + |
||
181 | '</OBJECT>' |
||
182 | ); |
||
183 | }; |
||
184 | |||
185 | // Stop Play (TStopPlay) |
||
186 | p.stopPlay = function(target){ |
||
187 | if(!this.isPlayerReady()) return; |
||
188 | if(target == null) target = "/"; |
||
189 | this.doc[this.playerID].TStopPlay(target); |
||
190 | }; |
||
191 | |||
192 | |||
193 | /* Static Functions & Properties --------------------------- */ |
||
194 | |||
195 | var fs = FlashSound; |
||
196 | fs.engage = true; // engage |
||
197 | fs.playerCount = 0; // player count |
||
198 | fs.players = new Array(); // players[] |
||
199 | fs.playerVersion = 0; // set playerVersion to 0 for unsupported browsers |
||
200 | |||
201 | |||
202 | // check for LiveConnect - Opera version 6.x with Java Enabled and Netscape versions 4.x but not greater |
||
203 | fs.LiveConnect = ((navigator.javaEnabled() && |
||
204 | (dynapi.ua.ns4 && dynapi.ua.v<5)) || dynapi.ua.opera6); |
||
205 | |||
206 | // browser compatibility check ----------------- |
||
207 | fs.supportedBrowser = ((dynapi.ua.ie && dynapi.ua.win32) || |
||
208 | dynapi.ua.ns6 || FlashSound.LiveConnect) ? true : false; |
||
209 | |||
210 | // player compatibility ------------------ |
||
211 | |||
212 | // checkForMinPlayer sets playerVersion for supported browsers |
||
213 | fs.checkForMinPlayer = function(){ |
||
214 | if(!this.supportedBrowser) return false; |
||
215 | if(dynapi.ua.ns6) { |
||
216 | // xpconnect works with version 6 r40 or greater |
||
217 | this.playerVersion = this.getPlugInVers(); // get version |
||
218 | releaseVers = this.getPlugInReleaseVers(); // get release version |
||
219 | //check release vers only for vers 6 |
||
220 | if(this.playerVersion == 6 && releaseVers >=40) return true; |
||
221 | } |
||
222 | |||
223 | if(this.LiveConnect) this.playerVersion = this.getPlugInVers(); |
||
224 | if(dynapi.ua.ie) this.playerVersion = (Flash_getActiveXVersion()); |
||
225 | |||
226 | if(this.playerVersion >= this.minPlayer) return true; |
||
227 | else return false; |
||
228 | }; |
||
229 | |||
230 | // check for flash plug-in in netscape |
||
231 | fs.checkForPlugIn = function(){ |
||
232 | var flashmimeType = "application/x-shockwave-flash"; |
||
233 | var hasplugin = (navigator.mimeTypes && navigator.mimeTypes[flashmimeType]) ? navigator.mimeTypes[flashmimeType].enabledPlugin : 0; |
||
234 | return hasplugin; |
||
235 | }; |
||
236 | |||
237 | // Get Plugin Version |
||
238 | fs.getPlugInVers = function(){ |
||
239 | if(this.checkForPlugIn()){ |
||
240 | var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin; |
||
241 | var pluginversion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) |
||
242 | return pluginversion; |
||
243 | }else{ |
||
244 | return 0; |
||
245 | } |
||
246 | }; |
||
247 | |||
248 | // Get Plugin Release Version |
||
249 | fs.getPlugInReleaseVers = function(){ |
||
250 | if(this.checkForPlugIn()){ |
||
251 | var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin; |
||
252 | var pluginversion = parseInt(plugin.description.substring(plugin.description.indexOf("r")+1, plugin.description.length)); |
||
253 | return pluginversion; |
||
254 | }else{ |
||
255 | return 0; |
||
256 | } |
||
257 | }; |
||
258 | |||
259 | // vers is integer |
||
260 | fs.setMinPlayer = function(vers){ |
||
261 | if(!this.supportedBrowser) return; |
||
262 | this.minPlayer = (vers != null && vers >= 4) ? vers : 4; |
||
263 | if(dynapi.ua.ns6) { |
||
264 | this.minPlayer = 6; // set min player to 6 for XPConnect |
||
265 | } |
||
266 | this.checkForMinPlayer(); |
||
267 | }; |
||
268 | |||
269 | // vbscript get Flash ActiveX control version for windows IE |
||
270 | if(dynapi.ua.ie && dynapi.ua.win32){ |
||
271 | var h='<scr' + 'ipt language="VBScript">' + '\n' + |
||
272 | 'Function Flash_getActiveXVersion()' + '\n' + |
||
273 | 'On Error Resume Next' + '\n' + |
||
274 | 'Dim hasPlayer, playerversion' + '\n' + |
||
275 | 'hasPlayer = false' + '\n' + |
||
276 | 'playerversion = 15' + '\n' + |
||
277 | 'Do While playerversion > 0' + '\n' + |
||
278 | 'hasPlayer = (IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" & playerversion)))' + '\n' + |
||
279 | 'If hasPlayer Then Exit Do' + '\n' + |
||
280 | 'playerversion = playerversion - 1' + '\n' + |
||
281 | 'Loop' + '\n' + |
||
282 | 'Flash_getActiveXVersion = playerversion' + '\n' + |
||
283 | 'End Function' + '\n' + |
||
284 | '<\/scr' + 'ipt>'; |
||
285 | |||
286 | if(!dynapi.loaded) document.write(h); |
||
287 | else { |
||
288 | dynapi.document.addChild(new DynLayer({w:0,h:0,visible:false,html:'<iframe name="FSVBS"></iframe'})); |
||
289 | var elm=document.frames['FSVBS']; |
||
290 | var doc = elm.document; |
||
291 | doc.open();doc.write(h);doc.close(); |
||
292 | dynapi.frame.Flash_getActiveXVersion = function() { |
||
293 | return elm.Flash_getActiveXVersion(); |
||
294 | }; |
||
295 | } |
||
296 | }; |
||
297 | |||
298 | // set minimum player version - default is 4 |
||
299 | fs.setMinPlayer(); |