PageSourceSearch

https://www.satan.lt/Common/JsClasses/Examples/System.Audio.js?v=20170525192438

js satan.lt collected 2026-10-03 00:50:46 UTC 19,449 bytes, 538 lines download raw bytes

1//=============================================================================
2// Jocys.com Audio Background Effects 1.1.0.0						2008-11-26
3//-----------------------------------------------------------------------------
4
5if (typeof System === "undefined") System = {};
6System.Audio = System.Audio ? System.Audio : {};
7System.Drawing = System.Drawing ? System.Drawing : {};
8System.Web = System.Web ? System.Web : {};
9
10//=============================================================================
11// CLASS: Uri
12//-----------------------------------------------------------------------------
13
14// If class exist then use that class.
15System.Uri = System.Uri ? System.Uri : function (uriString) {
16	/// <summary>
17	/// Initializes a new instance of the System.Uri class with the specified URI.
18	/// </summary>
19	/// <param type="string" name="uriString">A URI</param>
20	//---------------------------------------------------------
21	// http://www.domain.com:80/default.aspx?AudioMin=0&AudioMax=100
22	this.OriginalString;
23	// http://www.domain.com:80/default.aspx
24	this.AbsolutePath;
25	// ?AudioMin=0&AudioMax=100
26	this.Query;
27	this.QueryParams;
28	//---------------------------------------------------------
29	this.GetQueryValue = function (name, ignoreCase) {
30		var value = null;
31		var pName;
32		if (ignoreCase === true) name = name.toLowerCase();
33		for (var property in this.QueryParams) {
34			pName = property;
35			if (ignoreCase === true) pName = property.toLowerCase();
36			if (name === pName) {
37				value = this.QueryParams[property];
38				break;
39			}
40		}
41		return value;
42	};
43	//---------------------------------------------------------
44	this.GetParameters = function (uri) {
45		var results = {};
46		if (uri === null) return results;
47		var query = uri.substring(uri.indexOf("?") + 1, uri.length);
48		var arr = query.split("&");
49		var item;
50		var name;
51		var value;
52		for (var i = 0; i < arr.length; i++) {
53			item = arr[i];
54			name = item.substring(0, item.indexOf("="));
55			value = item.substring(item.indexOf("=") + 1, item.length);
56			value = unescape(value);
57			results[name] = value;
58		}
59		return results;
60	};
61	//---------------------------------------------------------
62	function initialize() {
63		var u = arguments[0];
64		this.OriginalString = u;
65		this.AbsolutePath = u.indexOf("?") > -1 ? u.substring(0, u.indexOf("?") - 1) : u;
66		this.Query = u.indexOf("?") > -1 ? u.substring(u.indexOf("?"), u.length) : null;
67		this.QueryParams = this.GetParameters(this.Query);
68	}
69	initialize.apply(this, arguments);
70};
71
72//-----------------------------------------------------------------------------
73
74// If class exist then use that class.
75System.Drawing.Point = System.Drawing.Point ? System.Drawing.Point : function (x, y) {
76	/// <summary>
77	/// Represents an ordered pair of integer x- and y-coordinates that defines a
78	/// point in a two-dimensional plane.
79	/// </summary>
80	//---------------------------------------------------------
81	this.X;
82	this.Y;
83	//---------------------------------------------------------
84	function initialize() {
85		this.X = arguments[0] ? arguments[0] : 0;
86		this.Y = arguments[1] ? arguments[1] : 0;
87	}
88	initialize.apply(this, arguments);
89};
90
91//-----------------------------------------------------------------------------
92
93System.Web.GetElementPagePoint = function (el) {
94	/// <summary>
95	/// Get coordinates of element.
96	/// </summary>
97	var p = new System.Drawing.Point();
98	el = typeof el === "string" ? document.getElementById(el) : el;
99	var elx = el;
100	var ely = el;
101	p.X = elx.offsetLeft;
102	while ((elx = elx.offsetParent) !== null) p.X += elx.offsetLeft;
103	p.Y = ely.offsetTop;
104	while ((ely = ely.offsetParent) !== null) p.Y += ely.offsetTop;
105	return p;
106};
107
108System.Web.GetMousePagePoint = function (e, relative) {
109	/// <summary>
110	/// Get coordinates of mouse pointer.
111	/// </summary>
112	var p = new System.Drawing.Point();
113	// FX.
114	if (window.Event) {
115		p.X = e.pageX;
116		p.Y = e.PageY;
117		if (relative) {
118			p.X += de.scrollLeft ? de.scrollLeft : document.body.scrollLeft;
119			p.Y += de.scrollTop ? de.scrollTop : document.body.scrollTop;
120		}
121	} else {
122		// IE.
123		var de = relative ? relative : document.documentElement;
124		p.X = event.clientX;
125		p.X += de.scrollLeft ? de.scrollLeft : document.body.scrollLeft;
126		p.Y = event.clientY;
127		p.Y += de.scrollTop ? de.scrollTop : document.body.scrollTop;
128	}
129	return p;
130};
131
132//-----------------------------------------------------------------------------
133
134System.Audio.PlayerType = {
135	XSPF: 1,
136	WMP: 2,
137	Embed: 3,
138	BGSound: 4
139};
140
141System.Audio.Player = function (playerType, playerId) {
142	//---------------------------------------------------------
143	this.Node;
144	this.PlayerType = 0;
145	var me = this;
146	//---------------------------------------------------------
147	this.SetVolume = function (volume) {
148		switch (this.PlayerType) {
149			case System.Audio.PlayerType.XSPF:
150				var v = Math.round(Math.pow(volume / 100, 3) * 100);
151				this.Node.SetVolume(volume);
152				break;
153			case System.Audio.PlayerType.WMP: this.Node.Settings.volume = volume; break;
154			case System.Audio.PlayerType.Embed: this.Node.SetVolume(Math.round(volume * 255 / 100)); break;
155			case System.Audio.PlayerType.BGSound:
156				var bv = Math.round((volume - 100) * 100);
157				document.getElementById("volinfo").innerHTML = bv;
158				this.Node.volume = bv;
159				break;
160		}
161	};
162	//---------------------------------------------------------
163	this.Stop = function () {
164		switch (this.PlayerType) {
165			case System.Audio.PlayerType.XSPF: this.Node.StopTrack(); break;
166			case System.Audio.PlayerType.WMP: this.Node.controls.stop(); break;
167			case System.Audio.PlayerType.Embed: this.Node.Stop(); break;
168			case System.Audio.PlayerType.BGSound: this.Node.controls.stop(); break;
169		}
170	};
171	//---------------------------------------------------------
172	this.Play = function () {
173		switch (this.PlayerType) {
174			case System.Audio.PlayerType.XSPF: this.Node.PlayTrack(); break;
175			case System.Audio.PlayerType.WMP: this.Node.controls.play(); break;
176			case System.Audio.PlayerType.Embed: this.Node.Play(true); break;
177			case System.Audio.PlayerType.BGSound: break;
178		}
179	};
180	//---------------------------------------------------------
181	this.Rewind = function () {
182		switch (this.PlayerType) {
183			case System.Audio.PlayerType.XSPF: this.Node.RewindTrack(); break;
184			case System.Audio.PlayerType.WMP: this.Node.controls.rewind(); break;
185			case System.Audio.PlayerType.Embed: this.Node.Rewind(); break;
186			case System.Audio.PlayerType.BGSound: break;
187		}
188	};
189	//---------------------------------------------------------
190	this.ChangeTrack = function (url, title) {
191		if (!title) {
192			title = unescape(url);
193			if (title.indexOf("/") > -1) {
194				var arr = title.split("/");
195				title = arr[arr.length - 1];
196			}
197		}
198		switch (this.PlayerType) {
199			case System.Audio.PlayerType.XSPF:
200				me.Node.StopTrack();
201				me.Node.LoadSong(unescape(url), title);
202				me.Node.LoadPlaylist();
203				window.setTimeout(function () { me.Play(); }, 500);
204				break;
205			case System.Audio.PlayerType.WMP: this.Node.URL = url; break;
206			case System.Audio.PlayerType.Embed: this.Node.src = url; break;
207			case System.Audio.PlayerType.BGSound: this.Node.src = url; break;
208		}
209	};
210	//---------------------------------------------------------
211	function initialize() {
212		var o = document.getElementById(playerId);
213		this.PlayerType = playerType;
214		if (o) {
215			this.Node = o;
216			return;
217		}
218		if (typeof playerType === "number") {
219			this.PlayerType = playerType;
220			switch (playerType) {
221				case System.Audio.PlayerType.XSPF:
222					// Flash palyer.
223					o = document.createElement("object");
224					o.setAttribute("id", playerId);
225					// http://musicplayer.sourceforge.net/#documentation
226					var data = "/Common/XSPF_Player/xspf_player_v3.6.swf?autoplay=1&song_url=";
227					o.setAttribute("type", "application/x-shockwave-flash");
228					o.setAttribute("style", "width: 100%; height: 18px;");
229					o.setAttribute("data", data);
230					var p1 = document.createElement("param");
231					p1.setAttribute("name", "movie");
232					p1.setAttribute("value", data);
233					o.appendChild(p1);
234					var p2 = document.createElement("param");
235					p2.setAttribute("name", "allowScriptAccess");
236					p2.setAttribute("value", "always");
237					o.appendChild(p2);
238					document.body.appendChild(o);
239					break;
240				case System.Audio.PlayerType.WMP:
241					// Windows Media player.
242					o = document.createElement("object");
243					o.setAttribute("id", playerId);
244					o.setAttribute("style", "width: 100%; height: 64px;");
245					var agent = navigator.userAgent.toLowerCase();
246					if (agent.indexOf("msie") > -1) {
247						o.setAttribute("classid", "clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6");
248					}
249					else if (agent.indexOf("firefox") > -1) {
250						o.setAttribute("type", "application/x-ms-wmp");
251					}
252					document.body.appendChild(o);
253					break;
254				case System.Audio.PlayerType.Embed:
255					// Embeded
256					o = document.createElement("embed");
257					o.setAttribute("volume", 0);
258					o.setAttribute("id", playerId);
259					o.setAttribute("type", "audio/x-mid");
260					o.setAttribute("style", "width: 100%; height: 64px;");
261					document.body.appendChild(o);
262					break;
263				case System.Audio.PlayerType.BGSound:
264					// Windows Media player.
265					o = document.createElement("object");
266					o.setAttribute("id", playerId);
267					o.setAttribute("style", "width: 100%; height: 64px;");
268					o.setAttribute("type", "audio/midi");
269					document.body.appendChild(o);
270					break;
271			}
272		}
273		this.Node = o;
274	}
275	initialize.apply(this, arguments);
276};
277
278//-----------------------------------------------------
279// Delayed Track Switching
280//-----------------------------------------------------
281
282System.Audio.TrackSwitcher = function (player) {
283	/// <summary>
284	/// Controls System.Audio.Player.
285	/// </summary>
286	//---------------------------------------------------------
287	this.Player;
288	//---------------------------------------------------------
289	var me = this;
290	// Used by PlayTrackTimeout method.
291	var currentTrack;
292	var currentTimerId = 0;
293	var currentDelay = 1000;
294	// Used by volume control methods.
295	this.VolumeStepIncrease = 10;
296	this.VolumeStepDecrease = 10;
297	this.VolumeStep;
298	this.Volume = 0;
299	this.VolumeMin = 0;
300	this.VolumeMinDefault = 0;
301	this.VolumeMax = 100;
302	this.VolumeMaxDefault = 100;
303	this.VolumenTimerAvailable = true;
304	this.RescheduleWhenVolumeZero = true;
305	var TrackRequested = null;
306	var TrackCurrent = null;
307	//---------------------------------------------------------
308	this.PlayTrackTimeout = function (track) {
309		/// <summary>
310		/// Swich to new track only if mouse spends some time on it.
311		/// In this case we will avoid track change if mouse will move
312		/// out from track area for very short period of time.
313		/// </summary>
314		if (currentTrack !== track) {
315			this.StopTrackTimeout();
316			currentTrack = track;
317			currentTimerId = window.setTimeout(function () {
318				me.SheduleTrackChange(track && track.href ? track : null);
319			}, currentDelay);
320		}
321	};
322	//---------------------------------------------------------
323	this.StopTrackTimeout = function () {
324		if (currentTimerId > 0) window.clearTimeout(currentTimerId);
325	};
326	//---------------------------------------------------------
327	this.SheduleTrackChange = function (track, increaseSound) {
328		TrackRequested = track;
329		// If current track is different from requested then...
330		if (TrackRequested !== TrackCurrent) {
331			// If volume is high then...
332			if (this.Volume > 0) {
333				// Decrease sound first.
334				if (TrackCurrent === null) {
335					this.Volume = 0;
336				} else {
337					this.DecreaseSound();
338					return;
339				}
340			}
341			if (this.Volume === 0) {
342				TrackCurrent = track;
343				if (track === null) {
344					this.Player.Stop();
345				} else {
346					// Analyse track info.
347					var uri = new System.Uri(track.href);
348					this.VolumeMin = uri.QueryParams.VolumeMin ? parseInt(uri.QueryParams.VolumeMin) : this.VolumeMinDefault;
349					this.VolumeMax = uri.QueryParams.VolumeMax ? parseInt(uri.QueryParams.VolumeMax) : this.VolumeMaxDefault;
350					// Change track.
351					this.Player.ChangeTrack(uri.AbsolutePath, track.title);
352					this.Player.SetVolume(this.Volume);
353					this.Player.Play();
354					if (increaseSound !== false) this.IncreaseSound();
355				}
356			}
357		} else {
358			if (TrackCurrent !== null && increaseSound !== false) {
359				this.IncreaseSound();
360			}
361		}
362	};
363	//---------------------------------------------------------
364	// This function will start decrease of volume.
365	this.DecreaseSound = function () {
366		this.VolumeStep = -1 * this.VolumeStepDecrease;
367		if (this.VolumenTimerAvailable) {
368			this.VolumenTimerAvailable = false;
369			this.StepSound();
370		}
371	};
372	//---------------------------------------------------------
373	this.IncreaseSound = function () {
374		this.VolumeStep = this.VolumeStepIncrease;
375		if (this.VolumenTimerAvailable) {
376			this.VolumenTimerAvailable = false;
377			this.StepSound();
378
379		}
380	};
381	//---------------------------------------------------------
382	// This function will increase || decrease background sound && restarts if(neccessary.
383	this.StepSound = function () {
384		var allow = false;
385		if (this.VolumeStep > 0) {
386			if (this.Volume < this.VolumeMax) allow = true;
387		} else {
388			if (this.Volume > this.VolumeMin) allow = true;
389		}
390		if (allow) {
391			// Count new sound value.;
392			var newVolume = this.Volume + this.VolumeStep;
393			if (newVolume > this.VolumeMax) newVolume = this.VolumeMax;
394			if (newVolume < this.VolumeMin) newVolume = this.VolumeMin;
395			this.Volume = newVolume;
396			// Convert value to create diferent volume fade.;
397			this.Player.SetVolume(this.Volume);
398			window.setTimeout(function () { me.StepSound(); }, 500);
399		} else {
400			this.VolumenTimerAvailable = true;
401		}
402		if (this.Volume === 0) {
403			// Try to set requested track again. 
404			if (this.RescheduleWhenVolumeZero) {
405				this.SheduleTrackChange(TrackRequested);
406			}
407		}
408	};
409	//---------------------------------------------------------
410	function initialize() {
411		this.Player = arguments[0];
412	}
413	initialize.apply(this, arguments);
414
415};
416
417//-----------------------------------------------------------------------------
418// System.Audio.Example
419//-----------------------------------------------------------------------------
420
421System.Audio.Example = {};
422
423System.Audio.Example.Player = null;
424System.Audio.Example.TrackSwitcher = null;
425System.Audio.Example.PageContentDiv = null;
426System.Audio.Example.Tracks = null;
427
428System.Audio.Example.PlayerInfo = function (s) {
429	document.getElementById("EyePosition").value = s;
430};
431
432System.Audio.Example.Window_Load = function (e) {
433	var items = document.getElementsByTagName("a");
434	System.Audio.Example.PageContentDiv = document.getElementById("PageContentScrollableDiv");
435	System.Audio.Example.Tracks = [];
436	for (var i = 0; i < items.length; i++) {
437		var item = items[i];
438		if (item.className === "Track") {
439			item.Point = System.Web.GetElementPagePoint(item);
440			System.Audio.Example.Tracks.push(item);
441		}
442	}
443	if (System.Audio.Example.Tracks.length === 0) return;
444	// Init Player
445	System.Audio.Example.Player = new System.Audio.Player(System.Audio.PlayerType.XSPF, "PlayerObject");
446	// Don't add player if already exists.
447	//document.getElementById("PlayerPlaceHolder").appendChild(Player.Node);
448	// Control Player through track switcher.
449	System.Audio.Example.TrackSwitcher = new System.Audio.TrackSwitcher(System.Audio.Example.Player);
450	// Attach events to checkbox.
451	var cbx = document.getElementById("AudioEnabledCheckBox");
452	if (window.attachEvent) cbx.attachEvent("onclick", System.Audio.Example.AudioEnabledCheckBox_Click);
453	else cbx.addEventListener("click", System.Audio.Example.AudioEnabledCheckBox_Click, true);
454	if (cbx.checked) System.Audio.Example.MouseTracking(true);
455};
456
457System.Audio.Example.AudioEnabledCheckBox_Click = function (e) {
458	window.setTimeout(System.Audio.Example.AudioEnableCheckBoxControl, 200);
459};
460
461System.Audio.Example.AudioEnableCheckBoxControl = function () {
462	var cbx = document.getElementById("AudioEnabledCheckBox");
463	if (cbx.checked) {
464		System.Audio.Example.MouseTracking(true);
465	} else {
466		System.Audio.Example.MouseTracking(false);
467		System.Audio.Example.TrackSwitcher.StopTrackTimeout();
468		System.Audio.Example.Player.Stop();
469	}
470};
471
472System.Audio.Example.Window_MouseMove = function (e) {
473	var y = 0;
474	if (window.attachEvent) {
475		y = System.Web.GetMousePagePoint(e, System.Audio.Example.PageContentDiv).Y;
476	} else {
477		y = e.pageY;
478		if (System.Audio.Example.PageContentDiv) y += System.Audio.Example.PageContentDiv.scrollTop;
479	}
480	System.Audio.Example.MouseResults(y);
481};
482
483System.Audio.Example.Window_MouseWheel = function (e) {
484	var y = 0;
485	var delta = 0;
486	if (window.attachEvent) {
487		// IE case, delta is multiple of 120
488		delta = event.wheelDelta / 120;
489		y = System.Web.GetMousePagePoint(e, System.Audio.Example.PageContentDiv).Y;
490	} else {
491		// FX case, delta is multiple of 3
492		delta = -e.detail / 3;
493		y = e.pageY - delta * 40 - 17 * delta;
494		if (System.Audio.Example.PageContentDiv) y += System.Audio.Example.PageContentDiv.scrollTop;
495	}
496	System.Audio.Example.MouseResults(y);
497};
498
499System.Audio.Example.MouseResults = function (y) {
500	var track = null;
501	for (var i = 0; i < System.Audio.Example.Tracks.length; i++) {
502		var t = System.Audio.Example.Tracks[i];
503		if (y >= t.Point.Y) track = t ? t : null;
504		if (y < t.Point.Y) break;
505	}
506	var file = track ? unescape(track.href) : "";
507	if (file.indexOf("/") > -1) {
508		var arr = file.split("/");
509		file = arr[arr.length - 1];
510	}
511	System.Audio.Example.PlayerInfo(" Vertical Mouse Position[" + y + "], V[" + System.Audio.Example.TrackSwitcher.Volume + "] " + System.Audio.Example.Tracks.length + "[" + i + "] " + file);
512	System.Audio.Example.TrackSwitcher.PlayTrackTimeout(track);
513};
514
515System.Audio.Example.MouseTracking = function (enable) {
516	/// <summary>
517	/// Enable/disable mouse tracking.
518	/// <summary>
519	if (enable) {
520		// Attach mouse events to windows.
521		if (window.attachEvent) document.attachEvent("onmousemove", System.Audio.Example.Window_MouseMove);
522		else document.addEventListener("mousemove", System.Audio.Example.Window_MouseMove, true);
523		// Attach scroll events to windows.
524		if (window.attachEvent) document.attachEvent("onmousewheel", System.Audio.Example.Window_MouseWheel);
525		else document.addEventListener("DOMMouseScroll", System.Audio.Example.Window_MouseWheel, true);
526	} else {
527		// Detach mouse events from windows.
528		if (window.detachEvent) document.detachEvent("onmousemove", System.Audio.Example.Window_MouseMove);
529		else document.removeEventListener("mousemove", System.Audio.Example.Window_MouseMove, true);
530		// Detach scroll events to windows.
531		if (window.attachEvent) document.detachEvent("onmousewheel", System.Audio.Example.Window_MouseWheel);
532		else document.removeEventListener("DOMMouseScroll", System.Audio.Example.Window_MouseWheel, true);
533	}
534};
535
536// Attach mouse movement events.
537if (window.attachEvent) window.attachEvent("onload", System.Audio.Example.Window_Load);
538else window.addEventListener("load", System.Audio.Example.Window_Load, true);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.