Skip to content

Instantly share code, notes, and snippets.

@frr149
Created October 24, 2012 21:24
Show Gist options
  • Save frr149/3948991 to your computer and use it in GitHub Desktop.
Save frr149/3948991 to your computer and use it in GitHub Desktop.
// Created by Fernando Rodríguez Romero on 24/10/12.
// Copyright (c) 2012 Agbo. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
if (argc < 2) {
// El primer parámetro es el nombre del ejecutable
// y el segundo debería de ser el fichero que vamos
// a examinar
NSLog(@"Uso: ametadatos /ruta/a/ficheroDeAudio");
return -1;
}
// Creo una NSString a partir de una cadena C y expando
// la tilde del directorio home
NSString *audioFilePath = [[NSString stringWithUTF8String:argv[1]]
stringByExpandingTildeInPath];
// Lo que me hace falta es una url
NSURL *audioURL = [NSURL fileURLWithPath:audioFilePath];
// Aquí empieza lo bueno: un "handle" para el fichero de audio
// los hombres de verdad comprueban errores con OSStatus
AudioFileID audioFile;
OSStatus err = noErr;
// Abrimos el fichero y necesitamos una CFURLRef en vez de un NSURL:
// son toll-free bridged
err = AudioFileOpenURL((__bridge CFURLRef)audioURL, kAudioFileReadPermission, 0, &audioFile);
assert(err == noErr);
// Obetengo el tamaño de los metadatos
UInt32 dictSize = 0;
err = AudioFileGetPropertyInfo(audioFile, kAudioFilePropertyInfoDictionary, &dictSize, 0);
assert(err == noErr);
// Los leo en un CFDictionaryRef (la versión CoreFoundation de NSDictionary)
CFDictionaryRef dict = NULL;
err = AudioFileGetProperty(audioFile, kAudioFilePropertyInfoDictionary, &dictSize, &dict);
assert(err == noErr);
// Imprimimos los datos que se hayan recuperado
NSLog(@"Meta datos: %@", dict);
// Hay que liberar los objetos CoreFoundation (qué cruz...)
CFRelease(dict);
// Cerramos el fichero
err = AudioFileClose(audioFile);
assert(err == noErr);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment