从NSTemporaryDirectory()打开音频文件时ExtAudioFileOpenURL失败

时间:2014-04-28 01:02:49

标签: ios objective-c audio openal objectal

我的应用从我的服务器下载小音频文件并将其存储在NSTemporaryDirectory()中。然后我使用ObjectAL(这是Karl Stenerud的OpenAL包装器库)将音频放在3D空间中。此库使用ExtAudioFile API打开和读取音频文件等。问题是,ExtAudioFileOpenURL()不允许读取任何文件,而不是[NSBundle mainBundle]中包含的本地文件。这实际上是真的吗?我可以成功打开/播放.mp3,.aif和.caf格式的音频文件,只要该文件包含在-mainBundle中。

如果确实如此,是否有办法使用驻留在ExtAudioFileOpenURL()(或任何其他iOS文件目录中的NSTemporaryDirectory()成功打开音频文件?以下是概述相关代码:

- (void)setSourceWithSourceURL:(NSString *)urlString type:(CueType)cueType volume:(ALfloat)vol isMono:(BOOL)mono isSFX:(BOOL)isSFX {

    ALSource *source = [self sourceForKey:cueType];
    ALBuffer *buffer = [self bufferForKey:cueType];
    if (!source) {
        source = [[ALSource source] retain];
    }
    if (!buffer) {
        NSArray *array = [urlString componentsSeparatedByString:@"/"];
        NSURL *furl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:array.lastObject]];

        buffer = [[[OpenALManager sharedInstance] bufferFromUrl:furl reduceToMono:mono] retain];
    }
    // fails when setting buffer...
}
在进行NSLog来电之前,furl的{​​{1}}输出为-bufferFromUrl

我确认该文件确实存在...

file:///private/var/mobile/Applications/08E20AF6-6333-4E24-9F12-20C6D6381C0B/tmp/4_right_turn_cue.aif调用基本上调用内部-bufferFromUrl: reduceToMono:方法:

-init

调用- (id) initWithUrl:(NSURL*) urlIn reduceToMono:(bool) reduceToMonoIn { if(nil != (self = [super init])) { url = as_retain(urlIn); reduceToMono = reduceToMonoIn; OSStatus error = 0; UInt32 size; if(nil == url) { OAL_LOG_ERROR(@"Cannot open NULL file / url"); goto done; } // Open the file if(noErr != (error = ExtAudioFileOpenURL((as_bridge CFURLRef)url, &fileHandle))) { REPORT_EXTAUDIO_CALL(error, @"Could not open url %@", url); goto done; } // ...more stuff but opening the URL fails 后,收到以下错误消息:

ExtAudioFileOpenURL()

有关为何无法从文件目录中读取音频文件的任何见解?任何想法或解决方法?

0 个答案:

没有答案