0
我有下面的代碼:IOS:系統聲音在模擬器上播放,但不能在iPhone上
soundFilenames = [[NSArray alloc] initWithObjects:@"Alarm Clock Bell.caf", @"Bark.caf", @"Cartoon Boing.caf", @"Chimpanzee Calls.caf", @"School Bell Ringing.caf", @"Sheep Bah.caf", @"Squeeze Toy.caf", @"Tape Rewinding.caf", nil];
...
-(void)playSound {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int index = rand() % [soundFilenames count];
NSString* filePath = [ [self getBasePath] stringByAppendingPathComponent: [soundFilenames objectAtIndex:index] ];
NSFileManager *fileManager = [NSFileManager defaultManager];
if([fileManager fileExistsAtPath:filePath])
NSLog(@"File %@ exists", [soundFilenames objectAtIndex:index]);
else
NSLog(@"File %@ NOT exists", [soundFilenames objectAtIndex:index]);
CFURLRef url = CFURLCreateWithFileSystemPath (0, (CFStringRef) filePath, kCFURLPOSIXPathStyle, NO);
SystemSoundID outSystemSoundID;
AudioServicesCreateSystemSoundID(url, &outSystemSoundID);
AudioServicesPlaySystemSound(outSystemSoundID);
[pool drain];
}
在模擬器和iPhone的輸出是這樣的:
2011-08-06 00:46:45.323 Alarm[199:5f03] File Cartoon Boing.caf exists
該代碼的問題:當我在模擬器中運行它時,一切正常,聲音正在播放,但是當我在我的iphone上運行它時,沒有聲音播放? (不會從主線程中調用方法,因此不會從主線程中調用分離的自動釋放池)