I wanna write a board which hilight when users drag files upon it,
When i run the code the drop() function did work, However the dragOver() and dragLeave() function just do not work,anything wrong with my code? I edit and run this in the p5.js web editor. just feel confused.
Hi, I’m really new to P5js, I was watching a tutorial for this same topic and is working perfectly, but I would like to do the same with audio, but it seams like the “.data” method doesn’t work with audio files, I know there is a SounFile object but I cannot figure out how to implemented with this example.
Hi micuat
Thank you so much for your reply, what I want to achieve is to be able to have a drag and drop area for the user to upload audio files, eventually I assume that I will need to save those files on a server (I think I can do it with the getBlob method), but first things first. My code right now is pretty simple, it’s working with images, but my logic on how to combine it with “loadSound” method is not.
let dropzone;
let img;
function setup() {
dropzone = select('#dropzone');
dropzone.dragOver(highlight);
dropzone.dragLeave(unhighlight);
dropzone.drop(gotFile, unhighlight);
}
function gotFile(file) {
createP(file.name + " " + file.size);
//createP(file.type);
//createP(file.subtype);
//(createP(file.size);
//img = createImg(file.data);
//save(img, 'myImage.png');
//img.size(100, 100);
img = loadSound(file);
}
function highlight() {
dropzone.style('background-color', '#ccc');
function unhighlight() {
dropzone.style('background-color', '#fff');
}
I’ll start watching the solution with native web audio that you placed.
Ei, @micuat thank you so much!! This is exactly what I was looking for, I already was working with the example that you send before and trying to figure out how to use it, but I think this one already helps me a lot.
I don’t want to keep bothering you, but I don’t compleatly understand how you get loadSound to start working with file.data; do you mind telling me where I can found more resources and information about that.
Again thank you much!
I think you had to start the playback - but unlike preload you have to use callback in this case…
For the question “where to find resource” it’s hard to answer because it was a bit of p5.js / javascript knowledge and some guessing work… I think p5.js reference is always a good place to start with, sometimes you need to look into the source code but I know this is intimidating, and you can always ask here when you think what you’re trying is beyond the “standard” p5.js