This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

This sketch demonstrates how to use the loadSnippet method of Minim. The loadSnippet method allows you to specify the file you want to load with a String. Unlike with loadFile and loadSample, you are not able to specify a buffer size because an AudioSnippet doesn't give you access to the samples as they are played.

Minim is able to load wav files, au files, aif files, snd files, and mp3 files. When you call loadSnippet, if you just specify the filename it will try to load the file from the data folder of your sketch. However, you can also specify an absolute path (such as "C:\foo\bar\thing.wav") and the file will be loaded from that location (keep in mind that won't work from an applet). You can also specify a URL (such as "http://www.mysite.com/mp3/song.mp3") but keep in mind that if you run the sketch as an applet you may run in to security restrictions if the applet is not on the same domain as the file you want to load. You can get around the restriction by signing the applet.

AudioSnippet is a simple wrapper around a JavaSound Clip (It isn't called AudioClip because that's an interface defined in the package java.applet). It provides almost the exact same functionality, the main difference being that length, position, and cue are expressed in milliseconds instead of microseconds. One of the limitations of AudioSnippet is that you do not have access to the audio samples as they are played. However, you are spared all of the overhead associated with making samples available. An AudioSnippet is a good choice if all you need to do is play a short sound at some point. If your aim is to repeatedly trigger a sound, you should use an AudioSample instead.

Before you exit your sketch make sure you call the close method of any AudioSnippet's you have received from loadSnippet.

Source code: loadSnippet

Built with Processing