[comp.sys.mac.programmer] Playing SND resources

peirce@outpost.UUCP (Michael Peirce) (01/22/91)

In article <1991Jan21.154725.15365@mthvax.cs.miami.edu>, rsherman@mthvax.cs.miami.edu (Roby Sherman) writes:
> 
> Does anyone know of a short, no-nonsense routine to play a SND resource? I
> don't have Inside Mac volume 5, so I have no idea how to make a Sound
> Manager call! HELP! thanks...

The simpliest was would be to do something like the following:

PROCEDURE PlayMySound;
CONST
	kMySoundID = -4065;
VAR
	h		: Handle;
	stat	: OSErr;
BEGIN
	IF TrapAvailable(_SndPlay, ToolTrap)
		THEN BEGIN
			h	:= GetResource('snd ',kMySoundID);
			IF h <> NIL 
				THEN BEGIN
					HLock(h);
					stat := SndPlay(NIL,h,kSYNC);
					HUnlock(h);
				END;
		END;
END;

-- michael


--  Michael Peirce         --   outpost!peirce@claris.com
--  Peirce Software        --   Suite 301, 719 Hibiscus Place
--  Macintosh Programming  --   San Jose, California 95117
--           & Consulting  --   (408) 244-6554, AppleLink: PEIRCE

lsr@Apple.com (Larry Rosenstein) (01/22/91)

In article <0B010004.sef8uo@outpost.UUCP>, peirce@outpost.UUCP (Michael Peirce) writes:
> 
 					HLock(h);
> 					stat := SndPlay(NIL,h,kSYNC);
> 					HUnlock(h);

I don't think you have to lock the snd resource if you are playing it
synchronously.  SndPlay will do that for you.  You do have to lock it if
you play it asynchronously, because the SndPlay call will usually return
before the sound is finished.

It doesn't hurt to play it safe, however.

Larry

gv9b2c9z@umiami.ir.miami.edu (Ordinary Man) (01/23/91)

In article <1991Jan21.154725.15365@mthvax.cs.miami.edu>, rsherman@mthvax.cs.miami.edu (Roby Sherman) writes:
> Does anyone know of a short, no-nonsense routine to play a SND resource? I
> don't have Inside Mac volume 5, so I have no idea how to make a Sound
> Manager call! HELP! thanks...
> 
> 		     -- Roby

Yeah, that goes for me, too. I've been having a hell of a time trying to
get the Sound Manager to play a 'snd' resource. It either crashes, plays
the sound only once when called, or doesn't play it at all. Please, help
if you can. (Send sample code if you have any). Thanks a lot,

				--Dan

-- 
/-------------------------------------------------------------------------\
|   Dan Weisman -  University of Miami - Florida   |  ||   ||   ||   ||   |
|--------------------------------------------------|  ||   ||   ||\ /||   |
|   INTERNET  -----> gv9b2c9z@umiami.IR.Miami.edu  |  ||   ||   || | ||   |
|     BITNET  -----> gv9b2c9z@umiami               |  |||||||   || | ||   |
|-------------------------------------------------------------------------|
|      "...bows it's head and prays to the mother of all machines."       |
\_________________________________________________________________________/

231b3679@fergvax.unl.edu (CS 231 section 2) (01/24/91)

gv9b2c9z@umiami.ir.miami.edu (Ordinary Man) writes:

>In article <1991Jan21.154725.15365@mthvax.cs.miami.edu>, rsherman@mthvax.cs.miami.edu (Roby Sherman) writes:
>> Does anyone know of a short, no-nonsense routine to play a SND resource? I
>> don't have Inside Mac volume 5, so I have no idea how to make a Sound
>> Manager call! HELP! thanks...
>> 
>> 		     -- Roby

>Yeah, that goes for me, too. I've been having a hell of a time trying to
>get the Sound Manager to play a 'snd' resource. It either crashes, plays
>the sound only once when called, or doesn't play it at all. Please, help
>if you can. (Send sample code if you have any). Thanks a lot,

If you can, get a hold of the Usenet Macintosh Programmer's Guide (UMPG)
which Matt Mora so thoughtfully compiled and posted to sumex for us. I am
anxiously awaiting to get a hold of that Sample Code note from apple that
will have a bunch of handy examples in it, but Mark Johnson at Apple said it
won't be available by FTP until ftp.apple.com is up and running :-(

--mike