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 04-18-2011, 03:25 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 13
dlaro is on a distinguished road
Default How do you lock audio from playing until current sound is done?

How do you lock audio from playing until current sound is done?

i have a simple audio sound that plays once the designated button is hit. i DON"T want any other sound to play until that clip is complete. how would i lock that button and any other audio buttons from being pressed until the current playing clip is complete?
dlaro is offline   Reply With Quote
Old 04-18-2011, 03:34 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 13
dlaro is on a distinguished road
Default

forgot to include my code. this is how i am implementing it.

using AVFoundation/AVFoundation Framework

-(IBAction)playSoundid)sender{

NSString *path = [[NSBundle mainBundle]pathForResource:@"bazzel1" ofType:@"wav"];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];

[audioPlayer play];

}
dlaro is offline   Reply With Quote
Old 04-18-2011, 03:57 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by dlaro View Post
forgot to include my code. this is how i am implementing it.

using AVFoundation/AVFoundation Framework

-(IBAction)playSoundid)sender{

NSString *path = [[NSBundle mainBundle]pathForResource:@"bazzel1" ofType:@"wav"];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];

[audioPlayer play];

}
Read the docs on AVAudioPlayer. You can set yourself as the delegate for a player, and implement a method that gets called when the sound completes. In that method, start the next sound playing.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 04-18-2011, 04:20 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 13
dlaro is on a distinguished road
Default

i can see the reference to the AVAudioPlayer in the help docs but cannot decipher what it's saying. i am pretty new at the dev game. any chance you have any sample code to show how would integrate with my existing code?

thanks!
dlaro is offline   Reply With Quote
Old 04-18-2011, 05:18 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by dlaro View Post
i can see the reference to the AVAudioPlayer in the help docs but cannot decipher what it's saying. i am pretty new at the dev game. any chance you have any sample code to show how would integrate with my existing code?

thanks!
Sigh...

Move your audio player object from a local variable to an instance variable in the class that contains your playSoundid method. Then add an @property (nonatomic, retain) statement in the header file, and and @synthesize statement. If you don't know how to do those things, go find Brian Slick's guide to properties in the tutorials section.

You might also want to read the memory management guide that is in the XCode docs. It's pretty easy to follow, and absolutely critical that you understand. There are a few simple rules to follow with handling memory in Cocoa, and if you follow them, you won't have any problems with leaking memory or over-release crashes. If you don't learn the rules early and follow them scrupulously, you will write apps that crash unexpectedly, run out of memory, and will get very frustrated.

Now, the 2 lines you need to add to your code:


Code:
-(IBAction)playSoundid)sender{
//AVAudioPlayer *audioPlayer;
NSString *path = [[NSBundle mainBundle]pathForResource:@"bazzel1" ofType:@"wav"];
self.audioPlayer = [[AVAudioPlayer alloc]
  initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL] autorelease];

audioPlayer.delegate = self;

[audioPlayer play];
}
Then add a method like this to your class:

Code:
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
//Create and play your second sound, since the first sound is done playing.
}
That last method is a delegate method. By setting your class up as the delegate for the audio player, the audio player will call any of the methods in the AVAudioPlayerDelegate Protocol that you define.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
audio

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: 352
14 members and 338 guests
dansparrow, dre, ilmman, LezB44, lorrettaui53, Nobbsy, Objective Zero, oztemel, pbart, samdanielblr, shagor012, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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