Reputation: 3234
My ViewController name is Mainviewcontroller in which i m doing all the actions of AVAudioplayer.
If in h file i do
@class MainViewController;
@protocol MainViewControllerDelegate
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)audioPlayer;
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)audioPlayer;
@end
@interface MainViewController : UIViewController <UIActionSheetDelegate, InfoDelegate, AVAudioPlayerDelegate>
I am confused in the above statement i m supposed to do AVAudioPlayerDelegate or MainViewControllerDelegate
If i do @protocolAVAudioPlayerDelegate then i get warning in yellow stating that duplicate protocol definition of AVAudioPlayer is ignored
when i have not defined @protocolAVAudioPlayer anywhere else.
Another confusion i have is that i m supposed to declare these methods in h file first only then implement in m file
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)audioPlayer;
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)audioPlayer;
Please help.
Upvotes: 0
Views: 1280
Reputation: 5028
I think you are mis-using the @protocol construct here. You can go ahead and drop the entire @protocol block and just implement your class. You simply need to indcate your class is a delegate for an instance of AVAudioPlayer like this:
@interface MainViewController : UIViewController <UIActionSheetDelegate, InfoDelegate, AVAudioPlayerDelegate>
Then when you instantiate your AVAudioPLayer object, be sure to assign the MainViewController as the delegate:
audioPlayInstance.delegate = self;
Lastly, implement the two methods you want to be called on your AVAudioPlayer instance (I called it audioPlayInstance above). You only need to put these in your .m file, NOT you header. The header declaration for these methods is handled by the AVAudioPlayer.h class file.
Good Luck!
Upvotes: 2