开发者

Problem with playing a sound when a button is clicked

in my code:

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


- (IBAction)pl开发者_运维问答aySound{
    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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜