Created
August 8, 2014 10:49
-
-
Save moonlit-g/8b5e46674d6b9134fda7 to your computer and use it in GitHub Desktop.
File API and Audio User Script Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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