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

Nsutton

macrumors member
Original poster
Dec 29, 2009
92
0
6 Feet Under
I'm working on a homer soundboard type app but I keep getting an error in xcode.
This code is for playing audio when a button is pushed.
Here's my code thats under the mainview.m.

Code:
#import "MainView.h"
#import <AVFoundation/AVAudioPlayer.h>

@implementation MainView
- (IBAction)pushButton {
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"Stupid" ofType:@"mp3"];	
	AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	theAudio.delegate = self;
	"WARNING: class 'MainView' does not implement the 'AVAudioPlayerDelegate' protocol"
       [theAudio play];
	
}
@end

Anyideas?
 
what's the error? Is it a compiler (gcc) error? Is it an actual Xcode app error? Does it crash the debugger?
 
I'm working on a homer soundboard type app but I keep getting an error in xcode.
This code is for playing audio when a button is pushed.
Here's my code thats under the mainview.m.

Code:
#import "MainView.h"
#import <AVFoundation/AVAudioPlayer.h>

@implementation MainView
- (IBAction)pushButton {
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"Stupid" ofType:@"mp3"];	
	AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	theAudio.delegate = self;
[COLOR="Red"]	"WARNING: class 'MainView' does not implement the 'AVAudioPlayerDelegate' protocol"[/COLOR]
       [theAudio play];
	
}
@end

Anyideas?

Try setting up your class to implement the AVAudioPlayerDelegate protocol?

http://en.wikibooks.org/wiki/Objective-C_Programming/in_depth#.22Inheritance.22_of_protocols
 
You are assigning self as delegate of AVAudioPlayer instance.

If you look in the reference:

Code:
delegate
The delegate object for the audio player.

@property (assign) id <AVAudioPlayerDelegate> delegate;
Discussion
The object that you assign to be an audio player’s delegate [B]becomes the target of the notifications described in AVAudioPlayerDelegate Protocol Reference[/B]. These notifications let you respond to decoding errors, audio interruptions (such as an incoming phone call), and playback completion.

The object you're assigning needs to conform to that protocol

So, as Detruis has just posted, your class should implement that.
 
Similar problem

I am using the AV Toolbox framework and received the same error. I am so new at Developing - I hope I can frame the question correctly. How would you change the code in the example below to make this work? Is the change needed in the Header file as well?

Thanks!
 
I am using the AV Toolbox framework and received the same error.

The key point is that the object you are assigning to must conform to the protocol. What this means is:

  1. Name the protocol(s) in the @interface definition ("Adopting a Protocol")
  2. Implement the required methods in the @implementation part ("Conforming to a Protocol")

It's worth reading http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html. Good luck :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.