{"id":580,"date":"2009-08-06T22:28:09","date_gmt":"2009-08-07T06:28:09","guid":{"rendered":"http:\/\/blog.mozilla.org\/webdev\/?p=580"},"modified":"2017-03-08T14:50:05","modified_gmt":"2017-03-08T22:50:05","slug":"html5-audio-soundboard","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/","title":{"rendered":"HTML5 Audio Soundboard"},"content":{"rendered":"<style type=\"text\/css\">\npre {\n    font-size:110%;\n}\n<\/style>\n<p>A few months ago, one of my <a href=\"http:\/\/micropipes.com\/blog\/\">famous web developer co-workers<\/a> had an <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=483119\">oh-so-special bug<\/a> filed against him requesting sound bites of some of his more famous sayings. He closed this bug with great success and all was well.<\/p>\n<p>Fast forward to today and not all is well. While we have our sound clips, they are not easily accessible; lying dormant on our hard drives and MP3 players. Well folks, today I have solved this problem. I give you the <a href=\"http:\/\/ryandoherty.net\/clouserwsoundboard\/\">ClouserW soundboard<\/a>:<\/p>\n<p><a href=\"http:\/\/ryandoherty.net\/clouserwsoundboard\/\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard.png\" alt=\"ClouserW soundboard\" title=\"ClouserW soundboard\" width=\"354\" height=\"412\" class=\"size-full wp-image-582\" srcset=\"https:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard.png 354w, https:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard-257x300.png 257w\" sizes=\"(max-width: 354px) 100vw, 354px\" \/><\/a><\/p>\n<p>(Firefox 3.5 or higher required)<\/p>\n<p>The <a href=\"http:\/\/github.com\/ryandoherty\/ClouserW-Soundboard\/blob\/11ef31f087fb47f5e04c3534c4f0f0ee749aabe4\/index.php\">page itself is pretty simple<\/a>, I use PHP to get a list of all the sound clips from a folder and insert an &lt;audio&gt; tag for each one. The real magic happens in JavaScript with jQuery:<\/p>\n<pre>\r\n$(\"audio\").removeAttr(\"controls\").each(function(i, audioElement) {\r\n    var audio = $(this);\r\n    var that = this;\r\n    $(\"#doc\").append($('&lt;button&gt;'+audio.attr(\"title\")+'&lt;\/button&gt;')\r\n        .click(function() {\r\n            that.play();\r\n        ));\r\n});\r\n<\/pre>\n<p>What I&#8217;m doing is first getting all the &lt;audio&gt; tags from the DOM and removing their &#8216;controls&#8217; attribute. What this does is removes all default UI supplied by the browser. I&#8217;m doing this instead of simply not putting the attribute there for users with JavaScript turned off. <strong>Edit:<\/strong> Controls do not show up if JavaScript is turned off due to <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=449358\">bug 449358<\/a>.<\/p>\n<p>Appended to that is .each(), which allows me to iterate over all of the &lt;audio&gt; tags individually. It will call the function I pass it once per each &lt;audio&gt; tag it finds. <\/p>\n<p>var audio = $(this); creates a new jQuery object from a normal DOM node, which gives me a few functions that make getting information from it easier.<\/p>\n<p>var that = this; is a closure to keep track of the current audio element inside the function for later execution. (Closures are outside of the realm of this blog post, if you&#8217;re interested in learning more about this powerful feature of JavaScript I recommend reading <a href=\"http:\/\/blog.morrisjohns.com\/javascript_closures_for_dummies\">this tutorial<\/a>).<\/p>\n<p>I then append a button to &lt;div id=&#8221;doc&#8221;&gt;. The button&#8217;s text is taken from the title attribute of the &lt;audio&gt; tag. <\/p>\n<p>Last, but not least, I attach a click handler to the button that uses the play() function of the audio tag I created a reference to above to play the soundclip.<\/p>\n<p>No muss, no fuss. And no Flash \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few months ago, one of my famous web developer co-workers had an oh-so-special bug filed against him requesting sound bites of some of his more famous sayings. He closed this bug with great success and all was well. Fast &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/\">Continue reading<\/a><\/p>\n","protected":false},"author":1438,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[288],"tags":[221,743,254],"coauthors":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HTML5 Audio Soundboard - Mozilla Web Development<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"mozilla\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/\",\"url\":\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/\",\"name\":\"HTML5 Audio Soundboard - Mozilla Web Development\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard.png\",\"datePublished\":\"2009-08-07T06:28:09+00:00\",\"dateModified\":\"2017-03-08T22:50:05+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/70ae25c16f09d053c6d8b5eac29dbda9\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#primaryimage\",\"url\":\"http:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard.png\",\"contentUrl\":\"http:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/webdev\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML5 Audio Soundboard\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/webdev\/\",\"name\":\"Mozilla Web Development\",\"description\":\"For make benefit of glorious tubes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/webdev\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/70ae25c16f09d053c6d8b5eac29dbda9\",\"name\":\"mozilla\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/image\/e77ee64829d0c3831212656324f746d1\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/75d2017e019c87560fe5d148a64659dc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/75d2017e019c87560fe5d148a64659dc?s=96&d=mm&r=g\",\"caption\":\"mozilla\"},\"url\":\"https:\/\/blog.mozilla.org\/webdev\/author\/mozilla-2\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML5 Audio Soundboard - Mozilla Web Development","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/","twitter_misc":{"Written by":"mozilla","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/","url":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/","name":"HTML5 Audio Soundboard - Mozilla Web Development","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/webdev\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#primaryimage"},"image":{"@id":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#primaryimage"},"thumbnailUrl":"http:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard.png","datePublished":"2009-08-07T06:28:09+00:00","dateModified":"2017-03-08T22:50:05+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/70ae25c16f09d053c6d8b5eac29dbda9"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#primaryimage","url":"http:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard.png","contentUrl":"http:\/\/blog.mozilla.org\/webdev\/files\/2009\/08\/soundboard.png"},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/webdev\/2009\/08\/06\/html5-audio-soundboard\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/webdev\/"},{"@type":"ListItem","position":2,"name":"HTML5 Audio Soundboard"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/webdev\/#website","url":"https:\/\/blog.mozilla.org\/webdev\/","name":"Mozilla Web Development","description":"For make benefit of glorious tubes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/webdev\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/70ae25c16f09d053c6d8b5eac29dbda9","name":"mozilla","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/image\/e77ee64829d0c3831212656324f746d1","url":"https:\/\/secure.gravatar.com\/avatar\/75d2017e019c87560fe5d148a64659dc?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/75d2017e019c87560fe5d148a64659dc?s=96&d=mm&r=g","caption":"mozilla"},"url":"https:\/\/blog.mozilla.org\/webdev\/author\/mozilla-2\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts\/580"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/users\/1438"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/comments?post=580"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts\/580\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/media?parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/categories?post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/tags?post=580"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/coauthors?post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}