English 中文(简体)
从iPod库读取.m4a原始数据
原标题:Reading .m4a raw data from iPod library

我正在使用AVAssetReaderTrackOutput从iPod库音乐原始数据,赛车WAV或MP3文件格式从iPod库工作得很好。然而,如果我读取M4A文件,我将获得所有0或垃圾的数据。。。我正在读取的M4A文件是可播放的,我确信它没有加密。。。当您读取M4A文件时,它似乎是iOS加密或输出0s。有人对如何解决这个问题有什么建议吗?

注意:如果我使用AVAssetExportSession从m4a文件导出到m4a文件,那么我会得到正确的原始数据,但这意味着我必须首先将其保存到磁盘(例如,在Apps文档文件夹中),然后读取它。我希望能够流式传输它,所以我需要找到直接读取它的方法。

这是我的代码,我得到正确的mp3或wav原始数据“除了m4a”:

NSURL *assetURL = [MediaItem valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];

AVAssetTrack* songTrack = [songAsset.tracks objectAtIndex:0];

AVAssetReaderOutput *assetReaderOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:[songAsset.tracks objectAtIndex:0] outputSettings:nil];

NSError *assetError = nil;
AVAssetReader *assetReader = [AVAssetReader assetReaderWithAsset:songAsset
                                                       error:&assetError];


[assetReader addOutput: assetReaderOutput];                

//Retain
self.mStreamAssetReader = assetReader;
self.mStreamAssetReaderOutput = assetReaderOutput;
问题回答

假设您所说的“原始音乐数据”是指原始PCM音频,您应该将初始化的NSDictionary与适当的参数一起传递到AVAssetReaderTrackOutput中,以便iOS为您解码.m4a文件中的AAC比特流。

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
    [NSNumber numberWithFloat:48000.0], AVSampleRateKey,
    [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
    [NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
    [NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey,
    [NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
    nil];

AVAssetReaderOutput *assetReaderOutput =
    [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:[songAsset.tracks objectAtIndex:0]
                                               outputSettings:settings];




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签