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」,但什麼也沒有發生在模擬器