문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

If you are not afraid of using the Terminal, mdls is probably the tool for you:

mdls /path/toYour/file
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top