{"id":21,"date":"2018-08-14T09:59:29","date_gmt":"2018-08-14T09:59:29","guid":{"rendered":"https:\/\/www.onlinenote.in\/jquery\/?p=21"},"modified":"2018-08-14T09:59:29","modified_gmt":"2018-08-14T09:59:29","slug":"audio-autoplay","status":"publish","type":"post","link":"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/","title":{"rendered":"Audio autoplay"},"content":{"rendered":"<pre class=\"lang:default decode:true \">window.addEventListener('load', () =&gt; {\r\n\t\t\t\t\/\/ noinspection JSUnresolvedVariable\r\n\t\t\t\tlet audioCtx = new (window.AudioContext || window.webkitAudioContext)();\r\n\t\t\t\tlet xhr = new XMLHttpRequest();\r\n\t\t\t\txhr.open('GET', 'audio-autoplay.wav');\r\n\t\t\t\txhr.responseType = 'arraybuffer';\r\n\t\t\t\txhr.addEventListener('load', () =&gt; {\r\n\t\t\t\t\tlet playsound = (audioBuffer) =&gt; {\r\n\t\t\t\t\t\tlet source = audioCtx.createBufferSource();\r\n\t\t\t\t\t\tsource.buffer = audioBuffer;\r\n\t\t\t\t\t\tsource.connect(audioCtx.destination);\r\n\t\t\t\t\t\tsource.loop = false;\r\n\t\t\t\t\t\tsource.start();\r\n\r\n\t\t\t\t\t\tsetTimeout(function () {\r\n\t\t\t\t\t\t\tlet t = document.createElement('p');\r\n\t\t\t\t\t\t\tt.appendChild(document.createTextNode((new Date()).toLocaleString() + ': Sound played'));\r\n\t\t\t\t\t\t\tdocument.querySelector('.output').appendChild(t);\r\n\t\t\t\t\t\t\tplaysound(audioBuffer);\r\n\t\t\t\t\t\t}, 1000 + Math.random()*2500);\r\n\t\t\t\t\t};\r\n\r\n\t\t\t\t\taudioCtx.decodeAudioData(xhr.response).then(playsound);\r\n\t\t\t\t});\r\n\t\t\t\txhr.send();\r\n\t\t\t});<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>window.addEventListener(&#8216;load&#8217;, () =&gt; { \/\/ noinspection JSUnresolvedVariable let audioCtx = new (window.AudioContext || window.webkitAudioContext)(); let xhr = new XMLHttpRequest(); xhr.open(&#8216;GET&#8217;, &#8216;audio-autoplay.wav&#8217;); xhr.responseType = &#8216;arraybuffer&#8217;; xhr.addEventListener(&#8216;load&#8217;, () =&gt; { let playsound = (audioBuffer) =&gt; { let source = audioCtx.createBufferSource(); source.buffer = audioBuffer; source.connect(audioCtx.destination); source.loop = false; source.start(); setTimeout(function () { let t = document.createElement(&#8216;p&#8217;); t.appendChild(document.createTextNode((new Date()).toLocaleString() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Audio autoplay - jQuery<\/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:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Audio autoplay - jQuery\" \/>\n<meta property=\"og:description\" content=\"window.addEventListener(&#039;load&#039;, () =&gt; { \/\/ noinspection JSUnresolvedVariable let audioCtx = new (window.AudioContext || window.webkitAudioContext)(); let xhr = new XMLHttpRequest(); xhr.open(&#039;GET&#039;, &#039;audio-autoplay.wav&#039;); xhr.responseType = &#039;arraybuffer&#039;; xhr.addEventListener(&#039;load&#039;, () =&gt; { let playsound = (audioBuffer) =&gt; { let source = audioCtx.createBufferSource(); source.buffer = audioBuffer; source.connect(audioCtx.destination); source.loop = false; source.start(); setTimeout(function () { let t = document.createElement(&#039;p&#039;); t.appendChild(document.createTextNode((new Date()).toLocaleString() [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/\" \/>\n<meta property=\"og:site_name\" content=\"jQuery\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-14T09:59:29+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/\",\"url\":\"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/\",\"name\":\"Audio autoplay - jQuery\",\"isPartOf\":{\"@id\":\"https:\/\/www.onlinenote.in\/jquery\/#website\"},\"datePublished\":\"2018-08-14T09:59:29+00:00\",\"dateModified\":\"2018-08-14T09:59:29+00:00\",\"author\":{\"@id\":\"\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.onlinenote.in\/jquery\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Audio autoplay\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.onlinenote.in\/jquery\/#website\",\"url\":\"https:\/\/www.onlinenote.in\/jquery\/\",\"name\":\"jQuery\",\"description\":\"Code Snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.onlinenote.in\/jquery\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Audio autoplay - jQuery","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:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/","og_locale":"en_US","og_type":"article","og_title":"Audio autoplay - jQuery","og_description":"window.addEventListener('load', () =&gt; { \/\/ noinspection JSUnresolvedVariable let audioCtx = new (window.AudioContext || window.webkitAudioContext)(); let xhr = new XMLHttpRequest(); xhr.open('GET', 'audio-autoplay.wav'); xhr.responseType = 'arraybuffer'; xhr.addEventListener('load', () =&gt; { let playsound = (audioBuffer) =&gt; { let source = audioCtx.createBufferSource(); source.buffer = audioBuffer; source.connect(audioCtx.destination); source.loop = false; source.start(); setTimeout(function () { let t = document.createElement('p'); t.appendChild(document.createTextNode((new Date()).toLocaleString() [&hellip;]","og_url":"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/","og_site_name":"jQuery","article_published_time":"2018-08-14T09:59:29+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/","url":"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/","name":"Audio autoplay - jQuery","isPartOf":{"@id":"https:\/\/www.onlinenote.in\/jquery\/#website"},"datePublished":"2018-08-14T09:59:29+00:00","dateModified":"2018-08-14T09:59:29+00:00","author":{"@id":""},"breadcrumb":{"@id":"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.onlinenote.in\/jquery\/audio-autoplay\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.onlinenote.in\/jquery\/"},{"@type":"ListItem","position":2,"name":"Audio autoplay"}]},{"@type":"WebSite","@id":"https:\/\/www.onlinenote.in\/jquery\/#website","url":"https:\/\/www.onlinenote.in\/jquery\/","name":"jQuery","description":"Code Snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.onlinenote.in\/jquery\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":""}]}},"_links":{"self":[{"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/posts\/21"}],"collection":[{"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":1,"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":22,"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/posts\/21\/revisions\/22"}],"wp:attachment":[{"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlinenote.in\/jquery\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}