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 07-28-2009, 08:35 PM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 15
Smile AVAudioPlayer stop

I'm trying to stop a sound with a button but cannot get it to work no matter what iv tried here is an example one of the things I have tried.

HEADER:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>

@interface MainView : UIView {
}

-(IBAction)sound1;
-(IBAction)stop;

@end

MAIN:

#import "MainView.h"

@implementation MainView

- (IBAction)sound1 {

NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
theAudio.delegate = self;
[theAudio play];

}

- (IBAction) stop {

NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
theAudio.delegate = self;
[theAudio stop];

}

@end

I know there is a simple way to do this but I'm completely lost.
Please help!
GeoffMilburn is offline   Reply With Quote
Old 08-14-2009, 07:17 PM   #2 (permalink)
Registered Member
 
blackyE's Avatar
 
Join Date: Aug 2008
Location: Germany
Posts: 78
Default

try this!

Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>

@interface MainView : UIView {
        
        AVAudioPlayer *theAudio;

}

-(IBAction)sound1;
-(IBAction)stop;

@end

MAIN:

#import "MainView.h"

@implementation MainView

- (IBAction)sound1 {

NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
theAudio.delegate = self;
[theAudio play];

}

- (IBAction) stop {

[theAudio stop];

}
blackyE is offline   Reply With Quote
Old 08-15-2009, 12:39 PM   #3 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 15
Default

that was one of the things I tried.. Doesn't work does anyone know how to stop audio??
GeoffMilburn is offline   Reply With Quote
Old 08-15-2009, 03:38 PM   #4 (permalink)
Registered Member
 
blackyE's Avatar
 
Join Date: Aug 2008
Location: Germany
Posts: 78
Default

do you have connect the code in the IB? or set prepareToPlay before theAudio play!
blackyE is offline   Reply With Quote
Old 08-30-2009, 11:56 AM   #5 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 15
Default

Quote:
Originally Posted by blackyE View Post
do you have connect the code in the IB? or set prepareToPlay before theAudio play!
thanks for the suggestions the code was connected and i just tried prepareToPlay but no luck.. this has stopped me from finishing my app for weeks now if there is anyone that has got this to work please help
GeoffMilburn is offline   Reply With Quote
Old 09-23-2009, 04:43 AM   #6 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 2
Default

change:
Quote:
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
to:
Quote:
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
I was having the same problem till I did that...
Azaric is offline   Reply With Quote
Old 09-26-2009, 10:39 AM   #7 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 15
Default

thank you so much it stops the sound but the sound is looping and when the playloop button is pressed more than once the stopsound button will only stop the first loop. any ideas?
GeoffMilburn is offline   Reply With Quote
Old 09-28-2009, 03:07 PM   #8 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 2
Default

Unless you want to have multiple instances of the sound playing like that I would check to see if the audio is playing and if it is then don't play it.

if(myAudio.playing != YES){
[myAudio play];
}
Azaric is offline   Reply With Quote
Reply

Bookmarks

Tags
avaudioplayer, sound, stop, stopping

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: 248
21 members and 227 guests
ADY, Alsahir, beleg_1998, Dani77, diyora, FAED, fredidf, iDifferent, iph_s, JamesCahall, JasonR, mer10, prchn4christ, Rudy, smithdale87, Speed, spiderguy84, stekki, tgjorgoski, timle8n1, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,755
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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