大佬教程收集整理的这篇文章主要介绍了iphone – 来自MPMediaItem的NSData,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_446_15@mPMediaItem *item = // obtain the media item NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Get raw PCM data from the track NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL]; NSMutableData *data = [[NSMutableData alloc] init]; const uint32_t sampleRate = 16000; // 16k sample/sec const uint16_t bitDepth = 16; // 16 bit/sample/chAnnel const uint16_t chAnnels = 2; // 2 chAnnel/sample (stereo) 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,AVLinearPCMIsFloatKey,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,size,outBytes); CMSampleBufferInvalidate(buffer); CFRelease(buffer); [data appendBytes:outBytes length:size]; free(outBytes);
以上是大佬教程为你收集整理的iphone – 来自MPMediaItem的NSData全部内容,希望文章能够帮你解决iphone – 来自MPMediaItem的NSData所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。