我为我的应用程序提供了适用于此声音的代码,但我不知道如何处理所有这些错误。
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)同样的错误在这条线上排名第一:
AudioServicesCreateSystemSoundID(soundfileURLRef,&amp; SoundID);
3)这是使用未经授权的标识符SoundID
AudioServicesPlaySystemSound(SoundID);
答案 0 :(得分: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);