Previous Book Contents Book Index Next

Inside Macintosh: Sound /
Chapter 1 - Introduction to Sound on the Macintosh / Sound Reference
Routines / Playing Sounds


Legacy Documentclose button

Important: Inside Macintosh: Sound is deprecated as of Mac OS X v10.5. For new audio development in Mac OS X, use Core Audio. See the Audio page in the ADC Reference Library.

SndPlay

You can use the SndPlay function to play a sound resource that your application has loaded into memory.

FUNCTION SndPlay (chan: SndChannelPtr; sndHdl: Handle; 
                  async: Boolean): OSErr;
chan
A pointer to a valid sound channel. You can pass NIL instead of a pointer to a sound channel if you want the Sound Manager to internally allocate a sound channel in your application's heap zone.
sndHdl
A handle to the sound resource to play.
async
A Boolean value that indicates whether the sound should be played asynchronously (TRUE) or synchronously (FALSE). This parameter is ignored (and the sound plays synchronously) if NIL is passed in the first parameter.
DESCRIPTION
The SndPlay function attempts to play the sound located at sndHdl, which is expected to have the structure of a format 1 'snd ' resource. If the resource has not yet been loaded, the SndPlay function fails and returns the resProblem result code. The handle you pass in the sndHdl parameter must be locked for as long as the sound is playing asynchronously.

The chan parameter is a pointer to a sound channel. If chan is not NIL, it is used as a valid channel. If chan is NIL, an internally allocated sound channel is used. Commands and data contained in the sound handle are then sent to the channel. Note that you can pass SndPlay a handle to some data created by calling the Sound Input Manager's SndRecord function as well as a handle to an actual 'snd ' resource that you have loaded into memory.

SPECIAL CONSIDERATIONS
Because the SndPlay function moves memory, you should not call it at interrupt time.

RESULT CODES
noErr0No error
notEnoughHardwareErr-201Insufficient hardware available
resProblem-204Problem loading the resource
badChannel-205Channel is corrupt or unusable
badFormat-206Resource is corrupt or unusable
SEE ALSO
For an example of how to play a sound resource using the SndPlay function, see "Playing a Sound Resource" on page 1-25. For more information on the SndPlay function, see the chapter "Sound Manager" in this book.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996