-1

我正在尝试制作一个简单的音频板应用程序,我正在关注 AVFoundationPlayer 上的 Apple 文档,但我一直收到此错误(“NSBundle”没有可见的@interface 声明选择器“pathForRescourc:ofType:”)并且我已经搜索过一个小时,没有结果。

我的 .h 文件

#import <UIKit/UIKit.h>
#import <AVFoundation/AVAudioPlayer.h>
@interface ViewController : UIViewController <AVAudioPlayerDelegate> {



}
//actions
-(IBAction)playSound1;
-(IBAction)playSound2;
-(IBAction)playSound3;
-(IBAction)playSound4;

@property (nonatomic, strong) AVAudioPlayer *player;

@结尾

我的 .m 文件

#import "ViewController.h"


@interface ViewController ()


@end



@implementation ViewController
@synthesize player;

- (void)viewDidLoad
{


    NSString *soundFilePath1 =
    [[NSBundle mainBundle] pathForRescource: @"trumpet"
                                     ofType: @"mp3"];

    NSURL *fileURL1 = [[NSURL alloc] initFileURLWithPath: soundFilePath1];


    AVAudioPlayer *newPlayer =
    [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL1 error:nil];

    [fileURL1 release];

    self.player= newPlayer;

    [newPlayer release];

    [player prepareToPlay];

    [player setDelegate: self];



    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@结尾

如果我可以提供任何其他详细信息,我将很乐意提供帮助并感谢您的阅读。

4

1 回答 1

2

这是一个错字。您已经编写了 pathForRecource: 并且它是pathForResource:ofType:.

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension

于 2013-11-11T21:36:54.003 回答