Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I load web media file? #12

Open
SamhwanKim opened this issue Nov 25, 2016 · 1 comment
Open

Can I load web media file? #12

SamhwanKim opened this issue Nov 25, 2016 · 1 comment

Comments

@SamhwanKim
Copy link

Is this library available by loading web media files, not drag and drop?

@ajhalls
Copy link

ajhalls commented Jul 21, 2017

I know this is old, but I figured out a way to do it by modifying the 'filedropbox.js' file. Just add an anchor tag with the class fileSelect to use, like this:
<a href="aug.wav" id="fileSelect">Select some files</a>

`/* Cross Browser Support */
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.BlobBuilder = window.WebKitBlobBuilder || window.MozBlobBuilder;
window.URL = window.URL || window.webkitURL;

/* The FileDropbox prepares a HTMLElement to be a drop container and loads the first dropped file into a array */
function FileDropbox()
{
this.result = null;
this.resultArrayBuffer = null;
this.onFinish = null;
this.onFail = null;

this.defineDropHandler = function defineDropHandler(dropContainerElement)
{
    // init event handlers
    dropContainerElement.addEventListener("dragenter", this.skipEventHandler, false);
    dropContainerElement.addEventListener("dragexit", this.skipEventHandler, false);
    dropContainerElement.addEventListener("dragover", this.skipEventHandler, false);
    dropContainerElement.addEventListener("drop", this.dropHandler, false);
    dropContainerElement.masterObj = this; // need to define this controller for further events
$('.fileSelect').click(function(e)
	{        
		var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
		var source;
		var audioData;

		function getData(audioFile) {

		  source = audioCtx.createBufferSource();
		  var request = new XMLHttpRequest();

		  request.open('GET', audioFile, true);

		  request.responseType = 'arraybuffer';


		  request.onload = function() {
				var audioData = request.response;
				dropContainerElement.masterObj.resultArrayBuffer = audioData;
				// write into the result array
				dropContainerElement.masterObj.result = new Uint8Array(audioData);
				
				// callback
				if (dropContainerElement.masterObj.onFinish !== null)
				{

					dropContainerElement.masterObj.onFinish();
				}

		  }
		  request.send();
		}

		e.stopPropagation();
		e.preventDefault();
		getData(e.currentTarget.href);

	}); 

};

};
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants