Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Danneman101

macrumors 6502
Original poster
Aug 14, 2008
361
1
How do you display controls for the AVAudioPlayer. I just want the stop-button at the bottom of the screen, but my code displays no controls at all. Ive been googling like a maniac for this, but nothing.

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:soundPathName ofType:@"mp3"];   
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];   
theAudio.delegate = self;   
[theAudio play];
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
I believe you need to provide your own controls and then have them call AVAudioPlayer's playback control methods. This is all described in more detail in the AVAudioPlayer Class Reference.
 

ghayenga

macrumors regular
Jun 18, 2008
190
0
How do you display controls for the AVAudioPlayer. I just want the stop-button at the bottom of the screen, but my code displays no controls at all. Ive been googling like a maniac for this, but nothing.

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:soundPathName ofType:@"mp3"];   
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];   
theAudio.delegate = self;   
[theAudio play];

Add a button to your view and and an IBAction to your viewController, connect them, and then call [theAudio stop] in your action method.
 

Danneman101

macrumors 6502
Original poster
Aug 14, 2008
361
1
Ok, thanks. Theyll probably add an interface in some comming version, I guess.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Theyll probably add an interface in some comming version, I guess.
Doubtful. It's meant more as an audio engine than a UI interface. Hence, the lack of the word 'Controller' in the class name. If they want to add an interface component, they will probably add a new AVAudioPlayerController class to the API.
 

ethana

macrumors 6502a
Jul 17, 2008
836
0
Seattle, WA
Super easy:

Code:
[I]In .h[/I]
- (IBAction)stopMusic;

[I]In .m[/I]
- (IBAction)stopMusic {
   [theAudio stop];
}

Connect the button to the stopMusic action method in Interface Builder.

Ethan
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.