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 10-18-2010, 08:30 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 3
damianh is on a distinguished road
Default AVAudioPlayer question

Hi,

I'm trying to setup a simple button that will allow me to play sound and stop a previous sound file. But unfortunately I have a problem with the way I have done this, when I press the button the audio starts but then if i press it again another instance starts and the files plays again.

Please can someone point me in the right direction? Thank you in advance.

CODE:

- (IBAction)soundFile {

NSString *playerPath = [[NSBundle mainBundle] pathForResource:@"sound_file" ofType:@"m4a"];

AVAudioPlayer* player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathlayerPath] error:NULL];
player.delegate = self;

[player stop];

[player play];

}

- (IBAction)soundFileTwo {

NSString *playerPath = [[NSBundle mainBundle] pathForResource:@"sound_file" ofType:@"m4a"];

AVAudioPlayer* player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathlayerPath] error:NULL];
player.delegate = self;

[player stop];

[player play];

}

Last edited by damianh; 10-18-2010 at 08:32 AM. Reason: mistake in code
damianh is offline   Reply With Quote
Reply

Bookmarks

Tags
avaudioplayer, play audio, stop 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: 340
7 members and 333 guests
Desert Diva, dre, hain, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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