Skip to content

Instantly share code, notes, and snippets.

@moonlit-g
Created August 8, 2014 10:49
Show Gist options
  • Save moonlit-g/8b5e46674d6b9134fda7 to your computer and use it in GitHub Desktop.
Save moonlit-g/8b5e46674d6b9134fda7 to your computer and use it in GitHub Desktop.
File API and Audio User Script Sample
// ==UserScript==
// @name FileAPIandAudioSample
// @namespace moonlit-g
// @version 0.1
// @description File API and Audio Sample
// @match http://*
// ==/UserScript==
jQuery.noConflict();
(function ($) {
$('body').append('<input id="shout" name="shout" type="file"/>');
// $('body').append('<div id="result"/>');
$('#shout').change( function( eo ) {
var file = eo.target.files[0];
if( /audio/.test( file.type ) ) {
// var html = '' +
// 'name: ' + file.name + '<br>' +
// 'size: ' + file.size + '<br>' +
// 'type: ' + file.type + '<br>';
// $('#result').append( html );
var reader = new FileReader();
reader.onload = function( ea ) {
var audio = new Audio( ea.target.result );
audio.play();
}
reader.readAsDataURL( file );
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment