My application is a viewer for a custom format, zip file with a well-defined XML manifest and resources such as images and movies. I use zlib to open a zip file in memory, and then go on to display the specified resources.
One problem I am facing is that I cannot display the video correctly, apparently because QTMovie cannot determine the mime type. A movie loaded from a file ([QTMovie movieWithFile]) works fine. Loaded from memory ([QTMovie movieWithData]) refuses to work.
This makes sense, since there is no file extension, QTMovie cannot determine mime type information. After a little search, I applied QTDataReference in the following mannner:
NSData *movieData = ...read from memory...; QTDataReference *movieDataReference = [[QTDataReference alloc] initWithReferenceToData:movieData name:fileName MIMEType:@"video/x-m4v"]; QTMovie *mov = [QTMovie movieWithDataReference:movieDataReference error:&err];
This works well, however hardcoding MIMEType is far from ideal. I have access to the file name and extension, so I tried to find the mime type using UTI (thanks to the good people at #macdev):
- (NSString*)mimeTypeForExtension:(NSString*)ext { CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,(CFStringRef)ext,NULL); return NSMakeCollectable(UTTypeCopyPreferredTagWithClass((CFStringRef)UTI,kUTTagClassMIMEType)); }
This, however, does not work. Obviously, there is an internal database of OS X extensions and corresponding mime types. Otherwise, movies from the disc will not work. How do I access it?
Thanks!
source share