AVM 프레임 워크에서 MPMusicPLayerController가 "멋지게"작동하지 않습니다. MPPlayerController를 사용하여 미디어 항목을 가져 와서 해당 항목에 대한 URL을 가져온 일부 DSP를 얻을 수있었습니다. AVURLAsset 과 AVAssetReader를 사용하십시오. 이런 식으로 :
MPMediaItem *currentSong = [myMusicController nowPlayingItem];
NSURL *currentSongURL = [currentSong valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:currentSongURL options:nil];
NSError *error = nil;
AVAssetReader* reader = [[AVAssetReader alloc] initWithAsset:songAsset error:&error];
AVAssetTrack* track = [[songAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
NSMutableDictionary* audioReadSettings = [NSMutableDictionary dictionary];
[audioReadSettings setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM]
forKey:AVFormatIDKey];
AVAssetReaderTrackOutput* readerOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:track outputSettings:audioReadSettings];
[reader addOutput:readerOutput];
[reader startReading];
CMSampleBufferRef sample = [readerOutput copyNextSampleBuffer];
while(sample != NULL)
{
sample = [readerOutput copyNextSampleBuffer];
if(sample == NULL)
continue;
CMBlockBufferRef buffer = CMSampleBufferGetDataBuffer(sample);
CMItemCount numSamplesInBuffer = CMSampleBufferGetNumSamples(sample);
AudioBufferList audioBufferList;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sample,
NULL,
&audioBufferList,
sizeof(audioBufferList),
NULL,
NULL,
kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment,
&buffer
);
for (int bufferCount=0; bufferCount < audioBufferList.mNumberBuffers; bufferCount++) {
SInt16* samples = (SInt16 *)audioBufferList.mBuffers[bufferCount].mData;
for (int i=0; i < numSamplesInBuffer; i++) {
NSLog(@"%i", samples[i]);
}
}
//Release the buffer when done with the samples
//(retained by CMSampleBufferGetAudioBufferListWithRetainedblockBuffer)
CFRelease(buffer);
CFRelease(sample);
그래서 AVURLAsset을 사용하여 파일에 직접 액세스 할 수 있었습니까? –
예, 사운드 데이터에 대한 전체 액세스 권한을 얻습니다. 나머지 코드에 대한 답변을 편집하여 실제 데이터를 봅니다. – ugiflezet
굉장해! 감사합니다 –