Page 1 of 1
blocking DOMless Audio (Audio API extension)
Posted: Sat Jun 18, 2011 9:15 pm
by al_9x
https://developer.mozilla.org/en/Introd ... _Extension
Audio API extension enables audio playback via the window.Audio object. It should be treated as a plug-in and (optional) blocked.
The crude way is with a surrogate:
user_pref("noscript.surrogate.Audio.sources", "@^https?:");
user_pref("noscript.surrogate.Audio.replacement", "window.Audio=null;");
but, it deserves window.java treatment.
Re: blocking DOMless Audio (Audio API extension)
Posted: Sun Jun 19, 2011 12:58 pm
by al_9x
What are you thoughts on blocking Audio()?
Re: blocking DOMless Audio (Audio API extension)
Posted: Sun Jun 19, 2011 1:12 pm
by Giorgio Maone
Sorry, I believed I had already answered but probably I just hit the "Preview" button.
Yes, it should be done that way.
Re: blocking DOMless Audio (Audio API extension)
Posted: Mon Jun 20, 2011 7:03 pm
by al_9x
document.createElement("audio") would also need to be blocked, don't know if there are other ways co construct the audio object.
Re: blocking DOMless Audio (Audio API extension)
Posted: Mon Jun 20, 2011 7:11 pm
by Giorgio Maone
al_9x wrote:document.createElement("audio") would also need to be blocked, don't know if there are other ways co construct the audio object.
Would this work also while the element is not inserted in a document?
Re: blocking DOMless Audio (Audio API extension)
Posted: Mon Jun 20, 2011 7:16 pm
by al_9x
Giorgio Maone wrote:al_9x wrote:document.createElement("audio") would also need to be blocked, don't know if there are other ways co construct the audio object.
Would this work also while the element is not inserted in a document?
Yes.
Re: blocking DOMless Audio (Audio API extension)
Posted: Mon Jun 20, 2011 7:23 pm
by Giorgio Maone
al_9x wrote:Giorgio Maone wrote:al_9x wrote:document.createElement("audio") would also need to be blocked, don't know if there are other ways co construct the audio object.
Would this work also while the element is not inserted in a document?
Yes.
PoC?
Re: blocking DOMless Audio (Audio API extension)
Posted: Mon Jun 20, 2011 7:53 pm
by al_9x
modified
https://developer.mozilla.org/User:sins ... _extension
Code: Select all
<!doctype html>
<html>
<head>
<title>Generating audio in real time</title>
<script type="application/javascript">
var notes = { "do": 3, "do#": 4, "re": 5, "re#": 6, "mi": 7, "fa": 8, "fa#": 9, "sol": 10, "sol#": 11, "la": 12, "la#": 13, "si": 14, "do+": 15 };
var clavier = { Q: "do", Z: "do#", S: "re", E: "re#", D: "mi", F: "fa", T: "fa#", G:"sol", Y:"sol#", H:"la", U:"la#", J:"si", K:"do+" };
var samples = new Float32Array(22050);
var octave = 3;
var DOM_KB = {};
for(k in clavier) DOM_KB[eval("KeyboardEvent.DOM_VK_"+k)] = clavier[k];
function playNOTE(note) {
var output = document.createElement("audio");
output.mozSetup(1, 44100);
var len = samples.length;
var f = 55 * Math.pow(2, octave + notes[note]/12);
for (var j = 0; j < samples.length ; j++) {
samples[j] = Math.sin( (j * f * Math.PI) / 44100);
}
output.mozWriteAudio(samples);
output = null;
}
function playKEY(e) {
if(e.charCode in DOM_KB)
playNOTE(DOM_KB[e.charCode], octave);
else switch(e.keyCode) {
case KeyboardEvent.DOM_VK_PAGE_UP : changeOctave(octave+1); break;
case KeyboardEvent.DOM_VK_PAGE_DOWN : changeOctave(octave-1); break;
}
return false;
}
function changeOctave(val) {
if(val<2) octave = 2;
else if(val > 8) octave = 8;
else octave = val;
}
</script>
</head>
<body onkeypress="playKEY(event);">
<button onclick="playNOTE('do');">Do</button>
<button onclick="playNOTE('re');">RĂ©</button>
<button onclick="playNOTE('mi');">Mi</button>
<button onclick="playNOTE('fa');">Fa</button>
<button onclick="playNOTE('sol');">Sol</button>
<button onclick="playNOTE('la');">La</button>
<button onclick="playNOTE('si');">Si</button>
<button onclick="playNOTE('do+');">Do</button>
</body>
</html>
Re: blocking DOMless Audio (Audio API extension)
Posted: Mon Jun 20, 2011 10:01 pm
by Giorgio Maone
Please check
latest development build 2.1.1.2rc6
Re: blocking DOMless Audio (Audio API extension)
Posted: Tue Jun 21, 2011 1:26 am
by al_9x
done