Skip to content

Instantly share code, notes, and snippets.

@sylae
Created April 1, 2014 02:38
Show Gist options
  • Save sylae/9906668 to your computer and use it in GitHub Desktop.
Save sylae/9906668 to your computer and use it in GitHub Desktop.
Play a local base64-encoded sound using buzz
<!DOCTYPE html>
<html>
<head>
<title>A test</title>
<script type="text/javascript" src="buzz/buzz.js"></script>
<script type="text/javascript">
var chat = new buzz.sound();
function encodeFile() {
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
var string = "";
reader.onloadend = function () {
chat = new buzz.sound(reader.result);
}
if (file) {
reader.readAsDataURL(file);
}
}
</script>
</head>
<body>
<h1>A test</h1>
<input type="file" onChange="encodeFile();" />
<input type="button" onclick="chat.play();" value="Click me"/>
<pre>Browser data:
-- PLAYS:
-- buzz main: <script type="text/javascript">if (!buzz.isSupported()) { document.write("No"); } else { document.write("Yes"); }</script>
-- buzz mp3: <script type="text/javascript">if (!buzz.isMP3Supported()) { document.write("No"); } else { document.write("Yes"); }</script>
-- buzz wav: <script type="text/javascript">if (!buzz.isWAVSupported()) { document.write("No"); } else { document.write("Yes"); }</script>
-- buzz aac: <script type="text/javascript">if (!buzz.isAACSupported()) { document.write("No"); } else { document.write("Yes"); }</script>
-- buzz ogg: <script type="text/javascript">if (!buzz.isOGGSupported()) { document.write("No"); } else { document.write("Yes"); }</script>
</pre>
</body>
</html>
@sylae
Copy link
Author

sylae commented Apr 1, 2014

Shoddy as hell, but a working proof of concept

@sylae
Copy link
Author

sylae commented Apr 1, 2014

also, there's a live preview (for now) on my sandbox, until i edit it in five months for some other stupid thing:

https://calref.net/~sylae/html5test/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment