2012-12-13 46 views
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”,但什么也没有发生在模拟器

回答

0

答案在这里:

Using Audio in Xcode

的之所以没有声音在模拟器中播放是因为当您使用时,

AudioServicesPlaySystemSound 

声音最长需要30秒。我使用的声音只是在它之上。如果有人知道如何使用超过30秒的声音文件,请发布代码:)将不胜感激。