Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is how I'm doing it in Objective-C:</p> <pre><code>#import &lt;CoreMedia/CoreMedia.h&gt; #import &lt;AVFoundation/AVFoundation.h&gt; #import &lt;CoreAudio/CoreAudio.h&gt; // or [NSURL URLWithString:@"ipod-library://item/item.mp3?id=2398084975506389321"] NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL]; NSMutableData *data = [[NSMutableData alloc] init]; const uint32_t sampleRate = 16000; const uint16_t bitDepth = 16; const uint16_t channels = 2; NSDictionary *opts = [NSDictionary dictionary]; AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:assetURL options:opts]; AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:asset error:NULL]; NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey, [NSNumber numberWithFloat:(float)sampleRate], AVSampleRateKey, [NSNumber numberWithInt:bitDepth], AVLinearPCMBitDepthKey, [NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved, [NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey, [NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey, nil]; AVAssetReaderTrackOutput *output = [[AVAssetReaderTrackOutput alloc] initWithTrack:[[asset tracks] objectAtIndex:0] outputSettings:settings]; [asset release]; [reader addOutput:output]; [reader startReading]; // read the samples from the asset and append them subsequently while ([reader status] != AVAssetReaderStatusCompleted) { CMSampleBufferRef buffer = [output copyNextSampleBuffer]; if (buffer == NULL) continue; CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(buffer); size_t size = CMBlockBufferGetDataLength(blockBuffer); uint8_t *outBytes = malloc(size); CMBlockBufferCopyDataBytes(blockBuffer, 0, size, outBytes); CMSampleBufferInvalidate(buffer); CFRelease(buffer); [data appendBytes:outBytes length:size]; free(outBytes); } [output release]; </code></pre> <p>Here <code>data</code> will contain the raw PCM data of the track. Please note that you cannot directly access the file of a song or video, only its data through this method. You can compress it using e. g. FLAC (<a href="https://github.com/H2CO3/PodMail/blob/master/PMViewController.m" rel="nofollow">that's how I'm processing it in my tweak</a>).</p> <p>Since MonoTouch has an 1:1 mapping to Objective-C class and method names, this should be fairly easy to copy over. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload