Skip to content

Instantly share code, notes, and snippets.

@azproduction
Forked from 140bytes/LICENSE.txt
Created January 17, 2012 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azproduction/1625831 to your computer and use it in GitHub Desktop.
Save azproduction/1625831 to your computer and use it in GitHub Desktop.
Tiny HTML5 Audio player

Tiny HTML5 Audio player

Usage:

var music = audio('http://people.mozilla.org/~roc/stream-demos/music2.webm'); // should play

window.setTimeout(function () {
    music.stop();
}, 50000);

Demo: http://jsfiddle.net/GYZ5b/2/

@tsaniel and @p01, thx for help

function(
s // audio source
){
return(s=new Audio(s)) // create instance, using source
.play(), // play
s // return instance for other stuff
}
function(s){return(s=new Audio(s)).play(),s}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mikhail Davydov <azazel.private@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "audio",
"description": "Tiny HTML5 Audio player",
"keywords": [
"audio",
"player",
"html5"
]
}
<!DOCTYPE html>
<title>Audio player</title>
<div>Expected value: <b>Music should be played</b></div>
<script>
var audio = function(s){return(s=new Audio(s)).play(),s}
audio('http://people.mozilla.org/~roc/stream-demos/music2.webm');
</script>
@tsaniel
Copy link

tsaniel commented Jan 17, 2012

Save some bytes.
function(s,a){return(a=new Audio).play(a.src=s),a}

@p01
Copy link

p01 commented Jan 17, 2012

Save more bytes:

function(s){s=new Audio(s);return s.play(),s}

@azproduction
Copy link
Author

@p01 brilliant golfing!

@tsaniel
Copy link

tsaniel commented Jan 17, 2012

One more byte
function(s){return(s=new Audio(s)).play(),s}

@p01
Copy link

p01 commented Jan 17, 2012

Duh! Nice one @tsaniel

@azproduction
Copy link
Author

http://people.mozilla.org/~roc/stream-demos/music2.webm is a good background music, btw :) Found it in sources of Mozilla MediaStream Processing API

@tsaniel
Copy link

tsaniel commented Jan 17, 2012

Interesting. Btw, waiting for your Tiny series :)

@jed
Copy link

jed commented Jan 20, 2012

heh, i think you've golfed this one out of usefulness!

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