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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 03-19-2010, 11:18 AM   #1 (permalink)
Registered Member
 
Whitehk's Avatar
 
Join Date: Feb 2010
Posts: 118
Default IBAction not responding to touch

I've created several apps using buttons, so I know this should be working. The deal is I'm trying to make a mute button to stop sound from playing. I don't get any errors when I compile, but when I load the app in the stimulator or on the phone, it doesn't do anything when I press the mute button. Here is how I implemented it:

Where I made the sound start playing:

- (void)viewDidLoad {
NSString *backgroundMusicPath = [[NSBundle mainBundle] pathForResource: @"Background Music" ofType: @"wav"];
NSURL *backgroundMusicURL = [[NSURL alloc] initFileURLWithPath:backgroundMusicPath];
AVAudioPlayer *backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:nil];
[backgroundMusic play];
backgroundMusic.numberOfLoops = -1;
}

The IBAction I used to stop the sound:

-(IBAction)muteTheSound:(UIButton *)button {
NSString *backgroundMusicPath = [[NSBundle mainBundle] pathForResource: @"Background Music" ofType: @"wav"];
NSURL *backgroundMusicURL = [[NSURL alloc] initFileURLWithPath:backgroundMusicPath];
AVAudioPlayer *backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:nil];
[backgroundMusic stop];
}


I know it's not a problem of connecting the button to the action in IB because I made SURE (100%) that I connected it correctly. Did I stop the music incorrectly? Is [backgroundMusic stop]; not what I should be using to stop the sound in this situation? Any replies would be appreciated. Thanks!
Whitehk is offline   Reply With Quote
Old 03-19-2010, 12:17 PM   #2 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 63
Default

Quote:
- (void)viewDidLoad {
NSString *backgroundMusicPath = [[NSBundle mainBundle] pathForResource: @"Background Music" ofType: @"wav"];
NSURL *backgroundMusicURL = [[NSURL alloc] initFileURLWithPath:backgroundMusicPath];
AVAudioPlayer *backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:nil];
[backgroundMusic play];
backgroundMusic.numberOfLoops = -1;
}
I think you should keep the reference of the backgroundMusic AVAudioPlayer you initaited in viewDidLoad, and stop the playing of this particular player in the IBAction function
__________________
My app: LyricBox(iPad ready for upload) more coming...
firearasi is offline   Reply With Quote
Old 03-19-2010, 02:30 PM   #3 (permalink)
Registered Member
 
Whitehk's Avatar
 
Join Date: Feb 2010
Posts: 118
Default

Quote:
Originally Posted by firearasi View Post
I think you should keep the reference of the backgroundMusic AVAudioPlayer you initaited in viewDidLoad, and stop the playing of this particular player in the IBAction function
If I do this, it will then give me an error saying backgroundMusic undeclared. I am at a complete loss here.
Whitehk is offline   Reply With Quote
Old 03-19-2010, 02:59 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 63
Default

Quote:
Originally Posted by Whitehk View Post
If I do this, it will then give me an error saying backgroundMusic undeclared. I am at a complete loss here.
Did you declare backgroundMusic as a member variable of your viewController?
__________________
My app: LyricBox(iPad ready for upload) more coming...
firearasi is offline   Reply With Quote
Old 03-19-2010, 02:59 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 20
Default

Quote:
Originally Posted by Whitehk View Post
I know it's not a problem of connecting the button to the action in IB because I made SURE (100%) that I connected it correctly. Did I stop the music incorrectly? Is [backgroundMusic stop]; not what I should be using to stop the sound in this situation? Any replies would be appreciated. Thanks!
Don't use IB. Wire up the events manually, then come back and report your findings.
frankenspank is offline   Reply With Quote
Reply

Bookmarks

Tags
avaudioplayer, background music, ibaction, mute, 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: 333
21 members and 312 guests
@sandris, ADY, BrianSlick, dacapo, Dani77, dre, HDshot, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, themathminister, timle8n1, tomtom100, vogueestylee, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,883
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, vvenkatachallam
Powered by vBadvanced CMPS v3.1.0

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