<embed src="epic-theme.mp3"></embed>
<object data="epic-theme.swf" type="application/x-shockwave-flash"> <param name="movie" value="epic-theme.swf" /> </object>
<audio src="epic-theme.mp3"></audio>
<video src="epic-intro.mp4"></video>
var audioContext; if(window.AudioContext){ audioContext = new window.AudioContext(); }
var audio = new Audio();
var audioBuffer; if(audioContext){ var request = new XMLHttpRequest(); request.open('GET', 'epic-theme.mp3', true); request.responseType = 'arraybuffer'; // Need to get an ArrayBuffer function decodeAudioData(e){ // async decode audioContext.decodeAudioData(e.target.response, function(buffer){ audioBuffer = buffer; }, onError); } request.addEventListener('load', decodeAudioData); request.send(); }
audio.src = 'epic-theme.mp3';
// Place to attach our buffer var source = audioContext.createBufferSource(); source.buffer = audioBuffer; source.connect(audioContext.destination); // destination = output source.start(0); // source.noteOn(0);
audio.play();
var gainNode = audioContext.createGain(); source.connect(gainNode); // Connect gainNode to destination instead of source gainNode.connect(audioContext.destination); gainNode.gain.value = 0.5; // Change gain (volume)
audio.volume = 0.5;
var audio = new Audio(); audio.canPlayType('audio/webm'); // "maybe" audio.canPlayType('audio/webm; codecs="vorbis"'); // "probably" audio.canPlayType('audio/obscure-type'); // ""
* Chrome on OSX
var audio = new Audio(); var sounds = [ { type: 'audio/mpeg', filename: 'epic-theme.mp3' }, { type: 'audio/webm', filename: 'epic-theme.webm' } ]; // Try the first sound that doesn't return '' sounds.some(function(sound){ return audio.canPlayType(sound.type) && (audio.src = sound.filename); }); // Chrome, IE, Safari, Some FF: audio.src === 'epic-theme.mp3' // Chromium, FF, Opera: audio.src === 'epic-theme.webm'
audio.addEventListener('error', function(){ // Filter the current sound from list sounds = sounds.filter(function(sound){ return audio.src.indexOf(sound.filename) < 0; }); // Try the next sound that doesn't return '' sounds.some(function(sound){ return audio.canPlayType(sound.type) && (audio.src = sound.filename); }); });
var sources = sounds.reduce(function(result, sound){ var canPlay = audio.canPlayType(sound.type); // Unshift the probablies onto beginning of the array if(canPlay === 'probably') result.unshift(sound.filename); // Push the maybes onto the end of the array if(canPlay === 'maybe') result.push(sound.filename); return result; }, []); audio.addEventListener('error', setSrc); // Use the first sound on the array - probablies before maybes function setSrc(){ sources.length && (audio.src = sources.shift()); } setSrc();
function load(filename){ var audio = new Audio(); // Replace static filenames with the variable passed in var sounds = [ { type: 'audio/mpeg', filename: filename + '.mp3' }, { type: 'audio/webm', filename: filename + '.webm' } ]; // All That Boilerplate return audio; } load('epic-theme').play(); load('sad-song').play();
define([ 'frozen/plugins/loadSound!epic-theme' ], function(theme){ // theme will be a Sound object based on Web Audio, // HTML5 Audio, or stubbed out if neither available // It will also try to use the best available codec theme.play(); });Frozen uses AMD plugins to make loading and using resources easier Can pass a filename without extension - auto determine which codec to use Also determines if WebAudio is available - defaults to that Then HTML5 Audio Otherwise stubbed out sound A lot of these headaches are already abstracted away from you
Causes the element to reset and start selecting and loading a new media resource from scratch.
Sets the paused attribute to false,
"In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not."
"This is intended. Autoplay is not honored on android as it will cost data usage."
We can download terabytes of images without any restrictions
var audio = new Audio(); audio.src = 'epic-theme.mp3'; function preloadSound(){ audio.load(); document.removeEventListener('touchstart', preloadSound); } document.addEventListener('touchstart', preloadSound);
var audio = new Audio(); audio.src = 'epic-theme.mp3'; function preloadSound(){ var vol = audio.volume; audio.volume = 0; audio.play(); audio.pause(); audio.volume = vol; document.removeEventListener('touchstart', preloadSound); } document.addEventListener('touchstart', preloadSound);
Yay Buzzwords
Enable in chrome://flags in Chrome Beta for Android