Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
130 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ border: none; | |
p { | ||
color: #eee; | ||
font-size: 18px; | ||
line-height: 1em; | ||
line-height: 1.2em; | ||
} | ||
|
||
p#data { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
|
||
<head> | ||
|
||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> | ||
|
||
<title>Untitled</title> | ||
|
||
<style type="text/css"> | ||
</style> | ||
|
||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | ||
|
||
<script type="text/javascript"> | ||
$(document).ready(function() { | ||
|
||
}); | ||
</script> | ||
|
||
<script type="text/javascript"> | ||
|
||
</script> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<div id="container"> | ||
<!--#echo var="DATE_LOCAL" --> | ||
</div><!-- container --> | ||
|
||
</body> | ||
|
||
</html> |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>Web Audio</title> | ||
<link rel="stylesheet" href="../css/main.css" /> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
|
||
<h1><a href="../index.html" title="simpl.info home page">simpl.info</a> Web Audio</h1> | ||
|
||
<audio autoplay controls> | ||
<source src="audio/animalSounds.ogv" type="audio/ogg" /> | ||
<source src="audio/animalSounds.mp3" type="audio/mp3" /> | ||
This browser does not support the audio element. | ||
</audio> | ||
|
||
<p>For more information about Web Audio see <a href="http://www.html5rocks.com/en/tutorials/webaudio/intro/" title="HTML5 Rocks tutorial: Getting started with the Web Audio API">Getting started with the Web Audio API</a>.</p> | ||
|
||
<script src="js/main.js"></script> | ||
|
||
<a href="view-source:http://simpl.info/webaudio" title="View source for this page" id="viewSource">View source</a> | ||
</div> | ||
<script src="../js/lib/ga.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// create an AudioContext | ||
// create an audio source node | ||
// connect it to a filter node | ||
// connect that a gain node | ||
// play sound! | ||
|
||
// cope with browser differences | ||
var context; | ||
if (typeof webkitAudioContext === "function") { | ||
context = new webkitAudioContext(); | ||
} else if (typeof AudioContext === "function") { | ||
context = new AudioContext(); | ||
} else { | ||
alert("Sorry! Web Audio is not supported by this browser"); | ||
} | ||
|
||
// use the audio element to create the source node | ||
var audioElement = document.querySelector("audio"); | ||
var sourceNode = context.createMediaElementSource(audioElement); | ||
|
||
// connect the source node to a filter node | ||
var filterNode = context.createBiquadFilter(); | ||
// see https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#BiquadFilterNode-section | ||
filterNode.type = 1; // HIGHPASS | ||
// cutoff frequency: for HIGHPASS, audio is attenuated below this frequency | ||
filterNode.frequency.value = 1760; | ||
sourceNode.connect(filterNode); | ||
|
||
// connect the filter node to a gain node (to change audio volume) | ||
var gainNode = context.createGainNode(); | ||
// default is 1 (no change); less than 1 means audio is attenuated, and vice versa | ||
gainNode.gain.value = 0.5; | ||
filterNode.connect(gainNode); | ||
|
||
// connect the gain node to the destination (i.e. play the sound) | ||
gainNode.connect(context.destination); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "data.json"); | ||
|
||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState === 4 && xhr.status === 200) { | ||
var data = JSON.parse(xhr.responseText); | ||
document.querySelector("#data").innerHTML = JSON.stringify(data); | ||
} | ||
} | ||
|
||
/* | ||
// can do this in Chrome, Firefox, etc.: | ||
xhr.onload = function(event) { | ||
var data = JSON.parse(this.response); | ||
document.querySelector("#data").innerHTML = JSON.stringify(data); | ||
} | ||
*/ | ||
|
||
xhr.send(); |
f0c1802
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably too late to ask, but what's the point of doing a
JSON.parse
only tostringify
in the next statement? File - xhr/js/main.jsf0c1802
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair question :).
The code is quite contrived, but it's really just to demonstrate how XHR can be used.