iPhoneでは、リソースのパスを取得する必要があります。OK、それはできましたが、CFURLCreateFromFileSystemRepresentationのことになると、これを解決する方法がわかりません。このエラーが発生するのはなぜですか?任意の解決策または回避策をいただければ幸いです。前もって感謝します。
iPhoneでAudioQueueを使用してオーディオを再生するために、SpeakHere、AudioQueueTools(SimpleSDKディレクトリから)およびAudioQueueTestの例を見てみました。パズルを組み立てようとして、これとあれをやってみました。今、私はこれで立ち往生しています。上記のsndFileからスローされた例外が原因で、プログラムがクラッシュしました。
私はAVAudioPlayerを使用してiPhoneゲームのすべてのサウンドを再生しています。実際のiPhoneデバイスでは、サウンドを再生するときに非常に時間がかかることが判明したため、AudioQueueを使用する必要があると判断しました。
- (id) initWithFile: (NSString*) argv{
if (self = [super init]){
NSString *soundFilePath = [[NSBundle mainBundle]
pathForResource:argv
ofType:@"mp3"];
int len = [soundFilePath length];
char* fpath = new char[len];
//this is for changing NSString into char* to match
//CFURLCreateFromFileSystemRepresentation function's requirement.
for (int i = 0; i < [soundFilePath length]; i++){
fpath[i] = [soundFilePath characterAtIndex:i];
}
CFURLRef sndFile = CFURLCreateFromFileSystemRepresentation
(NULL, (const UInt8 *)fpath, strlen(fpath), false);
if (!sndFile) {
NSLog(@"sndFile error");
XThrowIfError (!sndFile, "can't parse file path");
}
}