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
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?
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.
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.
PS: I have no idea whether this framework exists on iOS. You didn’t specify which OS you meant, so I’m assuming Mac :)