2013-05-11 56 views
0

我有適用於我的應用程序的聲音的代碼,但我不知道如何處理所有這些錯誤。使用未聲明的標識符soundfileURLRef

了代號爲ViewController.h IS(不會出現任何錯誤,但以防萬一您需要的信息):

#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的音樂」,CFSTR( 「帶」),NULL)

2)完全相同的ERROR AS#1在這條線:

AudioServicesCreateSystemSoundID(soundfileURLRef, & SoundID);

3)這具有未聲明的標識符的使用SoundID

AudioServicesPlaySystemSound(SoundID);

+0

什麼是你的聲音文件,擴展名? – 2013-05-11 03:30:08

回答

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);