Audioclip grabber   Leave a comment


call Sound.getClip(String path); with the path of the sound file

import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;
public class Sound
{
	public static String getUrl(File f)
	{
		String url = f.getAbsolutePath();
		String res = "";
		for (int i = 0; i < url.length(); i++)
		{
			if (url.charAt(i) == '\\')
			{
				res += '/';
			} else
				res += url.charAt(i);
		}
		url = "file:///" + res;
		return url;
	}

	public static AudioClip getClip(String path) throws MalformedURLException
	{
		return java.applet.Applet.newAudioClip(new java.net.URL(
				getUrl(new File(path))));
	}

}
Advertisements

Posted July 17, 2011 by epicrado in Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: