Registration for a type such as kUTTypeAudio is not registered for dragged files; It registers to drag and drop audio. It can work to receive any type of sound * dragged from another application, but not intended to receive files.
You will need to register for the type kUTTypeFileURL . Once you do this, any file that the user drags will close your drag and drop assignment methods. At this point, you cannot say "I need files, but only some types of files."
As a drag destination, you need to check the resistance (in draggingEntered: . Here you check if any files are an audio file or not. You have a choice of three approaches:
- Use the metadata structure to retrieve each type of file content. Expect this to happen for any file on a volume that does not have a Spotlight index.
- Use Service Launch to determine what type of content matches the specified file name extension. Error for any file that does not have a file name extension; should work as long as no file name extensions are ambiguous (this is not a problem for audio, AFAIK, but it can be a problem for certain extensions, such as "dat").
- Trying to interpret each file using a basic audio API / library and see if it succeeds.
If you get a content type (UTI) for one of the files, you will need to see if it is one of the types that you can handle.
- If you just play sound using NSSound, use
[NSSound soundUnfilteredTypes] . This returns a UTI array, so you are done; you can simply compare incoming UTIs with those in this array (using UTTypeEqual ). - If you use Audio File Services (or the next higher-level API, ExtAudioFile) to read each file, use
AudioFileGetGlobalInfo to get a list of type codes, and then use UTTypeCreatePreferredIdentifierForTag to convert each of OSType to UTI. - If you use any other library, you just need to see what it offers to evaluate what types it supports.
* If and only if incoming types are checked for compliance with any registered type, and not equality. If they are strictly checked for compliance with your registered types, you will need to register for certain types of audio that you can process.
source share