对于我的应用程序,我需要解码存储在NSData对象中的MP3文件.
出于安全原因,不希望将NSData对象写入磁盘并使用系统URL引用重新打开它,即使它仅在本地存储了一会儿.
我想利用扩展音频文件服务(或音频文件服务)来做到这一点,但是我无法获得NSData的表示,NSData只存在于内存中,可由这些音频文件服务读取.
编辑:我想解码MP3数据,以便我可以访问线性,PCM音频样本进行操作.从NSData对象回放不是问题.
我的代码如下:
decryptedData; //an NSData object which has already been initialized
const void *dataBytes = decryptedData.bytes; //pointer to the bytes in my NSData object
//this creates a CFURLRef from the pointer to the byte data
//I have printed out the resulting CFURL and have confirmed that it is indeed reading the bytes correctly
CFURLRef audioFileURLFromBytes = CFURLCreateWithBytes (kCFAllocatorDefault,
dataBytes,
decryptedData.length,
kCFStringEncodingASCII,
NULL);
//attempt to open the the URL using Extended Audio File Services
ExtAudioFileRef outExtAudioFile;
OSStatus err …Run Code Online (Sandbox Code Playgroud)