Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-18-2012, 02:23 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 2
robert wakeling is on a distinguished road
Default Playing sounds based on (id)sender...

Hi all,
I am totally new at this and am hoping to get my first simple app on to the app store but need some assistance if possible.
This is part of my .m file and what I'm hoping to do is play a sound whose filename matches the button id

-(IBAction)playSoundsid)sender {

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"0", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);


NSLog(@"The button id is: %i", [sender tag]);

The sound will play (currently 0.mp3) but in the CFStringRef part I would like it to play the relevant sound. There are 8 buttons and 8 sounds that go with them.
Like I say, a pointer in the right direction or a fix to this would be beneficial
Many thanks,
Rob

Last edited by robert wakeling; 01-18-2012 at 02:30 PM.
robert wakeling is offline   Reply With Quote
Old 01-18-2012, 02:32 PM   #2 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

Just replace the @"0" with

Code:
[NSString stringWithFormat:@"%i",[sender tag]]
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 01-18-2012, 02:46 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 2
robert wakeling is on a distinguished road
Default Thank you!

Thank you very much for the speedy reply! I literally copied your code in place of the @"0" and it threw an exception. The fix was to put a bridge in front of the CFStringRef but now it seems to work fine!

The line now reads:

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (__bridge CFStringRef) [NSString stringWithFormat:@"%i",[sender tag]], CFSTR ("mp3"), NULL);

And it seems to do what I want it to do now!
robert wakeling is offline   Reply With Quote
Old 01-18-2012, 03:02 PM   #4 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

Thats probably because you are using ARC.

I'm glad to have helped
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Reply

Bookmarks

Tags
cfstringref, sound

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 399
9 members and 390 guests
7twenty7, Atatator, glenn_sayers, guusleijsten, iphonedevshani, QuantumDoja, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:43 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0