Xcode Error?

Discussion in 'Mac Programming' started by Nsutton, Dec 30, 2009.

  1. Nsutton macrumors member

    Nsutton

    Joined:
    Dec 29, 2009
    Location:
    6 Feet Under
    #1
    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?
     
  2. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #2
    what's the error? Is it a compiler (gcc) error? Is it an actual Xcode app error? Does it crash the debugger?
     
  3. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #3
    Try setting up your class to implement the AVAudioPlayerDelegate protocol?

    http://en.wikibooks.org/wiki/Objective-C_Programming/in_depth#.22Inheritance.22_of_protocols
     
  4. robj macrumors regular

    Joined:
    Dec 23, 2009
    Location:
    Madrid, Spain
    #4
    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.
     
  5. mac2be4now macrumors newbie

    Joined:
    Jun 28, 2010
    Location:
    California
    #5
    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!
     
  6. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #6
    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 :)
     

Share This Page