The code limit to the media type to .mp3 and .aiff
The code limit to the media type to .mp3 and .aiff
- Subject: The code limit to the media type to .mp3 and .aiff
- From: Bright <email@hidden>
- Date: Wed, 8 Jul 2009 15:56:59 +0800 (CST)
Hi Every Friend,
In my app, my purpose is to limit the media type to the .mp3 and .aiff
only when I drag files into a table view. Other type is not allowed.
The code fragment is to limit the media type to mp3 and .aiff. When I
drag file into table view, MP3 file is OK. But the .aiff file can not be
drop into the table view.
I spent so much time but it is not useful. Could any body look over
the code for me and help me to solve it?
Thank you!! I will wait for your answer all the time.
Wish you good luck.
This is my code:
- (BOOL)isFileUTIMP3:(NSString *)filePath
{
BOOL isMP3File = NO,isAIFFFile=NO;
FSRef fileRef;
Boolean isDirectory;
if (FSPathMakeRef((constUInt8 *)[filePath fileSystemRepresentation], &fileRef, &isDirectory) == noErr)
{
CFDictionaryRef values = NULL;
CFStringRef attrs[1] = { kLSItemContentType };
CFArrayRef attrNames = CFArrayCreate(NULL, (constvoid **)attrs, 1, NULL);
if (LSCopyItemAttributes(&fileRef, kLSRolesViewer, attrNames, &values) == noErr)
{
if (values != NULL)
{
CFTypeRef uti = CFDictionaryGetValue(values, kLSItemContentType);
if (uti != NULL)
{
if (UTTypeConformsTo(uti, kUTTypeMP3))
{ isMP3File = YES; }
else
{ if(UTTypeConformsTo(uti, CFSTR("public.aiff-audio")))
isMP3File = YES;
}
CFRelease(values);
}
}
CFRelease(attrNames);
}
}
return isMP3File;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden