2011-07-24 33 views
1

我搜索了网站,并尝试了所有可能的选项,以使声音在我的iPhone应用程序中工作在模拟器上。在模拟器中工作的声音不在iphone 3GS

具体来说,我已经试过什么被建议在这里: Sound working in emulator, not in real iPhone

除了我试图从我的应用程序内的两个“.WAV”和“的.caf”文件,用下面的代码:

CFURLRef soundFileURLRef = NULL; 
soundFileURLRef = CFBundleCopyResourceURL (CFBundleGetMainBundle(), 
    CFSTR ("applause"),CFSTR ("wav"),NULL); 
NSLog(@"Clap Path: %s", CFURLGetString(soundFileURLRef)); 
AudioServicesCreateSystemSoundID (soundFileURLRef,&clappingFileID_); 

AudioServicesPlaySystemSound (clappingFileID_); 

基于其他的建议,我也改变了代码如下:

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDir = [paths objectAtIndex:0]; 
NSString *clapPath = [documentsDir 
         stringByAppendingPathComponent: @"applause.wav"]; 
// Put down default db if it doesn't already exist 
NSFileManager *fileManager = [NSFileManager defaultManager]; 
if (![fileManager fileExistsAtPath:clapPath]) { 
    NSString *defaultClapPath = [[NSBundle mainBundle] 
            pathForResource:@"applause" ofType:@"wav"]; 
    if (defaultClapPath) { 
     [fileManager copyItemAtPath:defaultClapPath toPath:clapPath error:NULL]; 
    } 
} 


// NSString *clapPath = [[NSBundle mainBundle] pathForResource:@"applause" ofType:@"caf"]; 
CFURLRef clapURL = (CFURLRef) [NSURL fileURLWithPath:clapPath]; 
AudioServicesCreateSystemSoundID (clapURL, &clappingFileID_); 

NSLog(@"calling initSounds.."); 
AudioServicesPlaySystemSound (clappingFileID_); 

上述两个代码段工作˚F或模拟器,但不适用于iphone。

  • 还通过执行getInfo检查.wav文件属性。它说: 比特率:176 kbps的 采样率:11.025 kHz的 试样尺寸:16位 大小62 KB

  • 还试图把它加通在iPhone上运行的.wav文件直接应用的上下文之外iTunes和这工作正常。这表明我的iPhone上的编解码器存在于给定的.wav文件中,并且它没有损坏。

我的手机操作系统是4.1及其iPhone 3GS。我编我的申请OS 3.2或以上的高达4.2

+0

为了显而易见,仿真器在设备不区分大小写时。你使用正确的文件名吗? –

+0

是的,音频文件名全是小写 – user200671

回答

0

尝试以下方法:在设备上进入设置,并调高音量上Sounds->铃声和警报

然后重试测试。

1

请确认iPhone上的静音开关处于关闭位置。

相关问题