2011-08-03 80 views
4

我通過AVAsset加載音頻資產。我想知道資產中有多少個通道(基本上是單聲道或立體聲)。做這個的最好方式是什麼?查找AVAsset的通道數

回答

8

這似乎是我正在尋找。

AVAssetTrack* songTrack = [mAssetToLoad.tracks objectAtIndex:0]; 
NSArray* formatDesc = songTrack.formatDescriptions; 
for(unsigned int i = 0; i < [formatDesc count]; ++i) { 
    CMAudioFormatDescriptionRef item = (CMAudioFormatDescriptionRef)[formatDesc objectAtIndex:i]; 
    const AudioStreamBasicDescription* bobTheDesc = CMAudioFormatDescriptionGetStreamBasicDescription (item); 
    if(bobTheDesc && bobTheDesc->mChannelsPerFrame == 1) { 
     mIsMono = true; 
    } 
}