这个问题真的很简单。我想模拟默认 OSX 的 Audio QuickLook 插件的行为,我需要 QuickTime Player,它通常位于预览窗口的底部。我还希望在使用我的自定义插件时,我还可以听到我当前正在预览的文件的声音。
下面是一些代码(来自 GeneratePreviewForURL.m 文件)可能有助于更好地理解上下文:
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
@autoreleasepool {
if (QLPreviewRequestIsCancelled(preview)) return noErr;
NSMutableString *html=[[NSMutableString alloc] init];
NSDictionary *props;
NSData *imageData=[NSData dataWithContentsOfFile:@"/tmp/IMAGE.png"];
props=@{
(__bridge NSString *)kQLPreviewPropertyTextEncodingNameKey:@"UTF-8",
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey:@"text/html",
(__bridge NSString *)kQLPreviewPropertyAttachmentsKey:@{
@"IMAGE":@{
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey:@"image/png",
(__bridge NSString *)kQLPreviewPropertyAttachmentDataKey: imageData,
},
},
};
[html appendString:@"<html>"];
[html appendString:@"<body>"];
[html appendString:@"<img src=\"cid:IMAGE\">"];
[html appendString:@"<br><br>"];
//...
[html appendString:@"</body>"];
[html appendString:@"</html>"];
QLPreviewRequestSetDataRepresentation(preview,(CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding],kUTTypeHTML,(CFDictionaryRef)props);
}
return noErr;
}