How do I play a sound in Mac OS?

2020-07-11 07:35发布

问题:

I want to play a .mp3 file in an Objective-C app being designed for use on Mac OS X Lion 10.7, not for the iPhone. Thanks!

回答1:

Take a look at the NSSound class:

NSSound *sound = [[NSSound alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3"] byReference:NO];
[sound play];
[sound release];