Quick validation of an audio file?

  • iOS 4.3 and 5.0.

    My app downloads (does not stream) audio files, and I want to be a good citizen and not assume they are actually audio files until I've verified them. What I can't do is this:

    + (BOOL) fileAtURLAppearsValid: (NSURL *) fileURL
    {
        AVURLAsset *    localAsset;
        localAsset = [AVURLAsset URLAssetWithURL: fileURL
                                        options: nil];
        return localAsset.readable && localAsset.playable;
    }

    because if the file is large, AVFoundation won't be able to examine it synchronously.

    And I'd like to have a synchronous check, even if it just means magic numbers and a sane file size. The problems are that I don't know what the magic numbers or sane sizes are; I don't necessarily have a filename extension; and I don't even know in advance what formats AVFoundation will accept on the machine I'm running on.

    Is there a library or something that can give me a quick-and-dirty assessment of an audio file?

    — F
  • On Thu, Nov 17, 2011 at 2:41 PM, Fritz Anderson <fritza...> wrote:
    > And I'd like to have a synchronous check,

    I think this is your mistake. Perform the check asynchronously. If it
    were possible to do what you wanted, AVFoundation would do it. Some
    file formats, like WAV, are infinitely extensible with arbitrary data
    and thus there's no concept of "sane" file size.

    --Kyle Sluder
  • On Nov 17, 2011, at 2:41 PM, Fritz Anderson wrote:

    > My app downloads (does not stream) audio files, and I want to be a good citizen and not assume they are actually audio files until I've verified them.

    IIRC, the AudioToolbox framework has code for this. Check AudioFile.h or ExtendedAudioFile.h.
    FYI, the coreaudio-api list would be the best place to ask more questions about this.

    —Jens

    PS: I have no idea whether this framework exists on iOS. You didn’t specify which OS you meant, so I’m assuming Mac :)
previous month november 2011 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
Go to today