Search code examples
cocoaaudioqtkitspotlight

examining audio file alternative to spotlight


i'm looking for an efficient alternative to grabbing audio file attributes in case spotlight is turned off.

Spotlight's MDItem attributes: kMDItemDurationSeconds, kMDItemAudioEncodingApplication, kMDItemAudioBitRate, kMDItemAudioSampleRate,kMDItemAudioChannelCount, kMDItemCodecs, are possible.

however QTKit's movieAttributes (if the file can be a QTMovie type), are not as complete, only QTMovieDurationAttribute fills my spec.

should i use Audio Format Services : OSStatus AudioFormatGetProperty, or is there something else, perhaps more light-weight that will suffice in the absence of MDItem information ?

i don't need to modify or play any files, i only need to know the property values.

thanks.


Solution

  • Get attributes from the audio track's media, not the movie. Here is an example of how to get duration in seconds.

    for (QTTrack* track in [movie tracks])
    {
        QTMedia* trackMedia = [track media];
    
        if ([trackMedia hasCharacteristic:QTMediaCharacteristicAudio])
        {
            QTTime mediaDuration = [(NSValue*)[trackMedia attributeForKey:QTMediaDurationAttribute] QTTimeValue];
            long long mediaDurationScaleValue = mediaDuration.timeScale;
            long long mediaDurationTimeValue = mediaDuration.timeValue;
            result = (double)mediaDurationTimeValue / (double)mediaDurationScaleValue;
            break;
        }
    }
    

    [trackMedia mediaAttributes] will give you other available attributes of the audio.