Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kwjohns

macrumors 6502a
Original poster
Jul 4, 2007
700
12
I'm trying to play a sound but it's not working.

Code:
if (sound == @"Song Name") {
		UIImage *image = [UIImage imageNamed: @"picture.png"];
		lyrics = [[UIImageView alloc] initWithImage: image];
		[self.view addSubview:lyrics];
		// Create pathname to sound file
		NSString *sndPath = [[NSBundle mainBundle]
							 pathForResource:@"song"
							 ofType:@"aif"
							 inDirectory:@"/"];
		// Create URL
		CFURLRef sndURL = (CFURLRef)[[NSURL alloc]
									 initFileURLWithPath:sndPath];
		
		// Create system sound ID
		AudioServicesCreateSystemSoundID(sndURL, &ssid);
		NSLog(@"%@\n", sndURL);		
		NSLog(@"%@\n", ssid);
		AudioServicesPlaySystemSound(ssid);
		
	}


I don't get any errors and the app runs fine but just no audio plays. The console shows this with my logs:

Code:
2009-02-16 10:01:39.407 Program[1370:20b] file://localhost/Users/username/Library/Application%20Support/iPhone%20Simulator/User/Applications/37D00767-4E08-4DCB-BA37-99B5BCBE2DC1/Program.app///song.aif
2009-02-16 10:01:39.408 Program[1370:20b] (null)

ssid is showing up as null? Any help is appreciated!
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
Try replacing

Code:
[[NSBundle mainBundle] pathForResource:@"song" ofType:@"aif" inDirectory:@"/"];

with

Code:
[[NSBundle mainBundle] pathForResource:@"song" ofType:@"aif"];
 

kwjohns

macrumors 6502a
Original poster
Jul 4, 2007
700
12
Try replacing

Code:
[[NSBundle mainBundle] pathForResource:@"song" ofType:@"aif" inDirectory:@"/"];

with

Code:
[[NSBundle mainBundle] pathForResource:@"song" ofType:@"aif"];

I got the same outcome.
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
It's working fine for me. You are running on the device and not simulator, right?

For reference, here's the exact code I'm using:

Code:
NSString *sndPath = [[NSBundle mainBundle] pathForResource:@"tock" ofType:@"caf"];
CFURLRef sndURL = (CFURLRef)[[NSURL alloc] initFileURLWithPath:sndPath];
SystemSoundID ssid;
AudioServicesCreateSystemSoundID(sndURL, &ssid);	
AudioServicesPlaySystemSound(ssid);
 

kwjohns

macrumors 6502a
Original poster
Jul 4, 2007
700
12
Nope, I am running it on the simulator. I haven't paid the fee to be able to run it on my phone. Was wanting to test the waters with some of this stuff before I jumped in by paying. Should ssid be returning null, though?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.