Allow user to select music files from computer into a processing sketch? - java

I'm creating a music visualiser. I am stuck on the part which allows the user to upload music tracks from their music library on their computer and have the visualiser respond to the beat of the specific song they have chosen.
I have used the minim library in Processing however I have to load the file name in the coding. I would like a way to have the user click a button which will open the file browser and allow them to select a track and then input that track into the player which will play the track and have the visualiser respond to the beats of the track.
I am not asking for code; rather I am asking on a way to go about this step by step. I am stuck on how to retrieve the files from the computer. I am not very good at coding so I am looking at libraries and tutorials online however; the videos I am finding on this topic only shows how to load text files into a sketch rather than a music file.

Sounds like you're looking for the selectInput() function.
From the reference:
void setup() {
selectInput("Select a file to process:", "fileSelected");
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
}
}
Opens a platform-specific file chooser dialog to select a file for
input. After the selection is made, the selected File will be passed
to the 'callback' function. If the dialog is closed or canceled, null
will be sent to the function, so that the program is not waiting for
additional input. The callback is necessary because of how threading
works.

Related

Android Radio App that streams my mp3 from a dropbox server

I have a dropbox media server that has a collection of mp3 files that I want to stream onto an android application.
I know that using the "MediaPlayer" is the best way to go in the API.
How my main concern is how do I automate the process, where music is being played one after another? As if it was like an internet radio app?
Could someone please point me in the correct location for guides or display example code would be great thank you in advance.
Place the music files names in an arraylist (e.g songs) then implement onCompletionListener then set it to your media player. Inside the listener restart the media player to play the next item.
myMediaPlayer.setOnCompletionListener(this);
public void onCompletion(MediaPlayer arg0) {
arg0.release();
if (counter < songs.size()) {
counter++;
arg0 = MediaPlayer.create(getApplicationContext(), songs.get(counter);
arg0.setOnCompletionListener(this);
arg0.start();
}
}
If the server gives apps audio files;put the files in a queue and play them using mediaplayer or another audio player.
Get first song from server and start playing it, meanwhile continue downloading other songs one by one.

Pasting text from clipboard using a button across different apps (Android)

I tried finding something similar on the net, but couldn't. What I want, specifically, is the ability to have a button paste some text that originated in some other app rather than the one I'm making. So, say you copy some text from the "Google Chrome" app and go through the regular long tap and copy. Then, you open this app and press a button and it fetches the text from the clipboard and pastes it in a TextView. I understand that this isn't possible with the clipboard manager since all the examples I've seen show it as an object that stores information from within the app.
No, ClipboardManager is a system service, providing access to a device-wide clipboard.
Part of the reason why many examples might show both copying and pasting to the clipboard is so that the example is self-contained.
So, you get a ClipboardManager from getSystemService(), get the current contents via getPrimaryClip(), and use the ClipData as you see fit.
For example, this sample project contains two apps: drag/ and drop/. Mostly, this is to illustrate cross-app drag-and-drop operations on Android 7.0. But, drop/ supports a "Paste" action bar item (with associated keyboard shortcut), where I grab whatever is on the clipboard and, if it has a Uri, use it:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.paste) {
boolean handled=false;
ClipData clip=
getSystemService(ClipboardManager.class)
.getPrimaryClip();
if (clip!=null) {
ClipData.Item clipItem=clip.getItemAt(0);
if (clipItem!=null) {
imageUri=clipItem.getUri();
if (imageUri!=null) {
showThumbnail();
handled=true;
}
}
}
if (!handled) {
Toast
.makeText(this, "Could not paste an image!", Toast.LENGTH_LONG)
.show();
}
return(handled);
}
return(super.onOptionsItemSelected(item));
}
There is no code in this app to put stuff on the clipboard, though the associated drag/ app has code for that.
I think what you want to achieve is available in this open-source library: https://github.com/heruoxin/Clip-Stack
The idea is that it keeps track of the clipboard entries in its own internal database while running a (in your case a floating button) service and then pasting that.

How to wait for user decision when downloading file

I want to continue with this question: How to download whole file from website. I find out that downloading a file is an automatic process and it doesn't wait for user decision cancel/save. So for example user writes url to download file and wait 1 minute. The file automatically starts downloading (I am using firefox) probably to the memory of the browser and when file is download then it continues processing code where I have logger "file successfully download" but there is still pop up window with decision cancel/save. So my question how I can wait for this decision and react on this.
Let's presume that you have an object that performs a download. You can make it implement Runnable and then make it run as a separate thread.
You can have a method called setDestination(String), and a method called cancel().
Cancel would be something like that:
public synchronized void cancel() {
this.cancelled = True;
}
And in the part where you actually perform the download you'd have a
if (this.cancelled) {
//remove downloaded data
return; //Exit from the download function
}
for the setDestination you would need to do something similar, store the download to a tempfile and at the end move it to the file indicated by destination.

GWT Clipboard Past Buffer

I maintain a GWT web application. Our users often upload screen shot image files via a standard file upload dialog. I'm trying to think of some slightly more user friendly approach. I was wondering if there might be any way to allow the users to "paste" the image data after clicking the print-screen button.
I read some other posts that said that GWT can't nativly copy anything to or read from the clipboard buffer, but what about if the user manually pastes the image via ctrl-V or right clicking and pasting.
If anybody knows how I can accomplish this in GWT or has any other ideas let me know.
There is an event for pasting:
com.google.gwt.user.client.Event.ONPASTE
I use this but only for pasting text (user must user Ctrl+V or right-click>Paste).
I guess there may be a way for you to use this.
To capture the event, I sink it to my Widget first:
sinkEvents(Event.ONPASTE | Event.ONKEYPRESS | Event.ONKEYDOWN | Event.ONFOCUS);
Then, I implement onBrowserEvent(Event):
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
switch (event.getTypeInt()) {
case Event.ONPASTE: paste(event);
}
}
Hope you can find a way to adapt this for images.

Java Applet play sound file has a different effect than Windows Media Player?

I have a Java program that auto dials phone numbers, it can generate sounds to mimic phone keypads, works fine for normal calls, but I encountered a problem when it comes to calling card, it requires me to enter a card number, the sounds generated by my program were not accepted by the other end, it always said the card number is incorrect, so I did some research and found a site that would generate the entire card number sound sequence for me, and I saved it, but the thing is when I used the following Java method to play the *.wav sound file, it's still not accepted, and yet if I play the same file back with Windows Media Player, the other end would accept it as a valid card number sound, why ? Does that mean Java Applet play sound file has a different effect than Windows Media Player ?
void playAudioFile(String File_Name)
{
try { Applet.newAudioClip(new URL("file:/"+File_Name)).play(); }
catch (Exception e) { e.printStackTrace(); }
}
If so, how can I, in my Java program, call Windows Media Player to play the sound ?
I tuned up the sound volume, now it works fine.
I can't tell you why exactly you are seeing this effect, but I can tell you how to launch Windows Media Player from your program.
Assuming Windows XP and Windows Media Player 11:
String myCommand = "\"C:\\Program Files\\Windows Media Player\\wmplayer\\\" /open \"" + File_Name + "\""
Runtime.getRuntime().exec(myCommand);
This will launch Windows Media Player and make it play the file that File_Name points to (full path would probably be safest). If Media Player is already open then it will still work :) Any currently playing file will be interrupted.
I hope this helps.

Categories

Resources