에 mpmediaitem를 개조했다 나는 찾아 냈다 (나가 찾아내는 방법을 주문을 받아서 만드는) MpMediaItem를 개조하고 mp3 파일을 얻는 방법. 아마 그것은 최선의 방법은 아니지만 작동합니다.객관적인 c는 - ogg vorbis
* .mp3 대신 * .ogg 파일을 구할 수있는 방법이 있습니까? 적절한 접근 방법은 무엇입니까?
-(void)exportMP3:(NSURL*)url toFileUrl:(NSString*)fileURL
{
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetReader *reader=[[AVAssetReader alloc] initWithAsset:asset error:nil];
NSMutableArray *myOutputs =[[NSMutableArray alloc] init];
for(id track in [asset tracks])
{
AVAssetReaderTrackOutput *output=[AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:track outputSettings:nil];
[myOutputs addObject:output];
[reader addOutput:output];
}
[reader startReading];
NSFileHandle *fileHandle ;
NSFileManager *fm=[NSFileManager defaultManager];
if(![fm fileExistsAtPath:fileURL])
{
[fm createFileAtPath:fileURL contents:[[NSData alloc] init] attributes:nil];
}else{
NSURL *url = [NSURL URLWithString:fileURL];
[fm removeItemAtURL:url error:nil];
[fm createFileAtPath:fileURL contents:[[NSData alloc] init] attributes:nil];
}
fileHandle=[NSFileHandle fileHandleForWritingAtPath:fileURL];
[fileHandle seekToEndOfFile];
AVAssetReaderOutput *output=[myOutputs objectAtIndex:0];
int totalBuff=0;
int test = 1;
while(test == 1)
{
CMSampleBufferRef ref=[output copyNextSampleBuffer];
if(ref==NULL)
test = 0;
if(ref==NULL)
break;
//copy data to file
//read next one
AudioBufferList audioBufferList;
NSMutableData *data;
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(ref, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
for(int y=0; y<audioBufferList.mNumberBuffers; y++)
{
AudioBuffer audioBuffer = audioBufferList.mBuffers[y];
void *frame = audioBuffer.mData;
data = [[NSMutableData alloc] initWithBytes:frame length:audioBuffer.mDataByteSize];
}
totalBuff++;
NSLog(@"\n%d\n",totalBuff);
int time = [self.mediaPlayer durationOfCurrentItem];
if (totalBuff * 2 <= time + 1)
[fileHandle writeData:data];
}
[fileHandle closeFile];
}
MP3 인코딩 코드가 올바르게 작동하면 [lame] (http://lame.sourceforge.net/)과 같은 제 3 자 라이브러리가 없으면 MP3 파일을 올바르게 인코딩 할 수 있습니다. ios에서 MP3 형식으로 오디오를 인코딩하는 것은 불가능합니다. mp3 파일 내부에서 다른 형식을 사용할 수있는 오디오 플레이어의 선의 때문에 단순히 작동하지 않으며 단순히 재생되지 않습니까? –