1
我在xcode中获得了以下设置,但没有声音出现。我有2个.wav文件工作之前,但其他.mp3和.wav文件不会工作,即时通讯想知道如果它的代码已被写入或如果它的声音文件?文件的比特率或大小是否有限制?请参阅下面的代码。我还将声音文件添加到项目中。.mp3&.wav Xcode中的文件
**ViewController.h**
import UIKit/UIKit.h
import AVFoundation/AVFoundation.h
import AudioToolbox/AudioToolbox.h
@interface ViewController :UIViewController
-(IBAction)AntlerRabbit;
@end
**ViewController.m**
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
-(IBAction)AntlerRabbit {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"AntlerRabbit", CFSTR("aiff"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (void)viewDidLoad
{
[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.
}
@end
然后我去MainStoryboard.storyboard并放置一个按钮,并将其链接到“AntlerRabbit”,但什么也没有发生在模拟器