views:

36

answers:

1

in my code:

#import "MyViewController.h"
#import "AVFoundation/AVAudioPlayer.h"


- (IBAction)playSound{
    AVAudioPlayer *myExampleSound;

    NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"myaudiofile" ofType:@"caf"];

    myExampleSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL];

    myExampleSound.delegate = self;

    [myExampleSound play];

}

But it is showing a warning that Class MyViewController does not implement AVAudioplayerDelegate.

Anyone please help. I had included the AVFoundation.Framework.

+2  A: 

That warning should not affect the actual function of the code.

If you want to suppress the warning, in the header of your view controller do this:

@interface MyViewController : UIViewController <AVAudioPlayerDelegate> {

This lets the compiler know that your class does respond to the AVAudioPlayerDelegate (even though all the methods in that protocol are optional). See here.

macatomy
It worked!! Thank you very much!!
iSharreth