FolderItem.OpenAsSound

From Xojo Documentation

Revision as of 19:06, 1 June 2017 by PLefebvre (talk | contribs)

(diff) ← Older revision | Approved revision (diff) | Latest revision (diff) | Newer revision → (diff)
Method

FolderItem.OpenAsSound() As Sound

Supported for all project types and targets.

Opens the FolderItem to be read and returns its contents as a sound object.

Notes

On macOS OpenAsSound recognizes sound formats that Core Audio can play.

On Windows WAVs, WMAs, MP3s, and MIDI files can be played, but only WAVs play with DirectSound (this allows individual pan and volume settings for each sound. You can also play multiple sounds simultaneously).

On Linux GStreamer, xine, or libsndfile is used (in that order if available). Nil is returned if the sound can't be read or isn't a sound file at all.

Example

This example loads a sound file called “hello.mp3” from the current directory (folder) into a Sound object and plays it.

Dim f As FolderItem
f = GetFolderItem("hello.mp3")

If f <> Nil And f.Exists Then
Dim s As Sound
s = f.OpenAsSound
s.Play
End If