

In other words, because the sound is preloaded into a clip, playback can start immediately instead of having to wait for the buffer to be filled. Finally, playback from a Clip generally has less latency than buffered playback from a SourceDataLine. If you need to start the playback at an arbitrary position in the sound, the Clip interface provides a method to do that easily. If you want the sound to play back more than once, a Clip is more convenient than a SourceDataLine, especially if you want the playback to loop (cycle repeatedly through all or part of the sound). Use a Clip when you have non-real-time sound data that can be preloaded into memory.įor example, you might read a short sound file into a clip.Although there are many situations in which you could use either a Clip or a SourceDataLine, the following criteria help identify which kind of line is better suited for a particular situation: The primary difference between the two is that with a Clip you specify all the sound data at one time, before playback, whereas with a SourceDataLine you keep writing new buffers of data continuously during playback.
#Play sound how to
Here you will learn how to play sound through a line.Īs you know, there are two kinds of line that you can use for playing sound: a The Java Sound API is designed to help application programs play sounds smoothly and continuously, even very long sounds.Įarlier you saw how to obtain a line from the audio system or from a mixer.

With sound even more than video, it's important that the rate of data flow be maintained, because interruptions to sound playback often produce loud clicks or irritating distortion. If the data is time-based, as sound is, it must be delivered at the correct rate. The essential feature is that a sequence of data is delivered somewhere for eventual perception by a user.

These are general terms that are applicable to other kinds of media besides sound. If the script is exited, any currently-playing file that it started will stop.Playback is sometimes referred to as presentation or rendering. To stop a file that is currently playing, use SoundPlay on a nonexistent filename as in this example: SoundPlay, Nonexistent.avi. On some systems, certain file types might stop playing even when an entirely separate script plays a new file. If a file is playing and the current script plays a second file, the first file will be stopped so that the second one can play. avi, etc.) might not be playable if the right codecs or features aren't installed on the OS.
#Play sound windows
RemarksĪll Windows OSes should be able to play. For more information, see Runtime Errors.ĮrrorLevel is set to 1 if there was a problem or 0 otherwise. : This command is able to throw an exception on failure. Known limitation: If the WAIT parameter is omitted, the OS might consider the playing file to be "in use" until the script closes or until another file is played (even a nonexistent file). Even while waiting, new threads can be launched via hotkey, custom menu item, or timer. To avoid this, specify 1 or the word WAIT, which causes the current thread to wait until the file is finished playing before continuing. If omitted, the script's current thread will move on to the next command(s) while the file is playing. To work around this, use other file types such as MP3 (with a path length of up to 255 characters) or use 8.3 short paths (see A_LoopFileShortPath how to retrieve such paths). Known limitation: Due to a quirk in Windows, WAV files with a path longer than 127 characters will not be played. If the sound card is not available, the sound is generated using the speaker. To produce standard system sounds, specify an asterisk followed by a number as shown below (note that the Wait parameter has no effect in this mode): The name of the file to be played, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. SoundPlay, Filename, Wait Parameters Filename Plays a sound, video, or other supported file type. SoundPlay - Syntax & Usage | AutoHotkey SoundPlay
