0

我已经为我的应用程序设置了声音代码,但我不知道如何处理所有这些错误。

ViewController.h 的代码是(没有出现错误,但以防万一您需要信息):

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>

@interface pstViewController : UIViewController

-(IBAction)playsound;


@end

ViewController.m IS 的代码(3 个错误):

#import "pstViewController.h"

@interface pstViewController ()

@end

@implementation pstViewController




-(IBAction)playsound;
{
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundfile;
    soundfileURLRef =CFBundleCopyResourceURL (mainBundle, (CFStringRef) @"Spaz Music"CFSTR             (    ("band"), NULL)
    UInt32 SoundID;
    AudioServicesCreateSystemSoundID(soundfileURLRef, &SoundID);
    AudioServicesPlaySystemSound (SoundID);

错误显示如下:

1) 在这条线上,错误表明使用了未声明的标识符 soundfileURLRef:

soundfileURLRef =CFBundleCopyResourceURL (mainBundle, (CFStringRef) @"Spaz Music", CFSTR ("band"), NULL)

2) 与这条线上的#1 完全相同的错误:

AudioServicesCreateSystemSoundID(soundfileURLRef, &SoundID);

3) 这使用了未声明的标识符 SoundID

AudioServicesPlaySystemSound (SoundID);

4

1 回答 1

0

播放短音片段,

 SystemSoundID soundID;

 if(soundID == 0){

    //play the myaudio.caff file in the main bundle 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"myaudio" ofType:@"caff"];
    NSURL *url = [NSURL fileURLWithPath:path];

    AudioServicesCreateSystemSoundId((CFURLRef) url, &soundID);
 }

 AudioServicesPlaySystemSound(soundID);
于 2013-05-11T03:32:03.163 回答