CoreAudio:读取AudioFileMarkerList的正确方法?

时间:2016-06-07 01:37:34

标签: objective-c swift core-audio audiotoolbox ezaudio

快速概述:我正在开发Mac Swift桌面音频应用程序。我遇到了一个似乎要求我点击AudioToolbox C api才能获得AudioFileMarkerList的情况。在任何较新的AVStuff中似乎都不支持这一点,因此您似乎仍需要使用AudioToolbox API。

我很想听到有经验处理这些C结构的人,甚至更好,将它们与Swift联系起来。或者,如果还有另一种方法可以从我失踪的声音文件中检索标记 - 我也很想知道它。

1 个答案:

答案 0 :(得分:1)

以下是答案,以防将来有人遇到此问题。

// get size of markers property (dictionary)
UInt32          propSize;
UInt32          writable;

[EZAudioUtilities checkResult:AudioFileGetPropertyInfo( self.audioFileID,
                                                       kAudioFilePropertyMarkerList,
                                                       &propSize,
                                                       &writable)
                    operation:"Failed to get the size of the marker list"];

size_t length = NumBytesToNumAudioFileMarkers( propSize );

// allocate enough space for the markers.
AudioFileMarkerList markers[ length ];

if ( length > 0 ) {
    // pull marker list
    [EZAudioUtilities checkResult:AudioFileGetProperty( self.audioFileID,
                                                       kAudioFilePropertyMarkerList,
                                                       &propSize,
                                                       &markers)
                        operation:"Failed to get the markers list"];

} else {
    return NULL;
}

//NSLog(@"# of markers: %d\n", markers->mNumberMarkers );