#import "StopSoundViewController.h"
@implementation StopSoundViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
theAudio = nil;
}
- (IBAction) soundButtonPressed:(UIButton *)button {
NSLog(@"SoundButton Pressed");
if (theAudio == nil) {
// Set up the player.
NSLog(@"Set up theAudio");
NSString *path = [[NSBundle mainBundle] pathForResource:@"boom" ofType:@"wav"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
else if ([theAudio isPlaying]) {
// there's no point in stopping it, if it's not playing...
NSLog(@"Stopping theAudio");
[theAudio stop];
}
else {
NSLog(@"Starting theAudio, again");
[theAudio play];
}
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
NSLog(@"Player Finished Playing");
}
/* if an error occurs while decoding it will be reported to the delegate. */
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error {
NSLog(@"Error Decode...");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
// I know that I haven't done this. This is just a sample.
}
@end
Since your sound is named "boom" it's probably not an issue for you, but stopping sounds can introduce a pretty noticeable click when the play is interrupted. I've done a couple of posts on this on our blog.
is there a way to get avaudio framework to play a listen.pls (shoutcast stream)
i know that the native quicktime player will play it on the iphone but i do not know how to make it browse to the url onload of my program
i have made a very crude iphone internet radio app using embed but no one on a iphone wants to click start when a program loads
i have a html fire embeded into a view so it can load the webpage and it works fine.