我是根据我的个人经验来回答这个问题的。
在 OSX 10.6.8 上使用 Xcode 4.2 可以在基于 HTML 的 QuickLook 插件中加载音频文件,只需使用 <audio> 标签的 <src> 属性:
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;
props=@{
(__bridge NSString *)kQLPreviewPropertyTextEncodingNameKey:@"UTF-8",
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey:@"text/html",
};
[html appendString:@"<html>"];
[html appendString:@"<body>"];
[html appendString:@"<audio src=\"/tmp/AudioFile.mp3\" type=\"audio/mpeg\" controls=\"true\" autoplay=\"true\" />"];
[html appendString:@"</body>"];
[html appendString:@"</html>"];
QLPreviewRequestSetDataRepresentation(preview,(CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding],kUTTypeHTML,(CFDictionaryRef)props);
}
return noErr;
}
现在,在 Mavericks 上使用 Xcode 5.1,似乎使用 cid: 方案(我将在下面发布一个示例)都无法完成这项工作:
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 *audioData=[NSData dataWithContentsOfFile:@"/tmp/AudioFile.mp3"];
props=@{
(__bridge NSString *)kQLPreviewPropertyTextEncodingNameKey:@"UTF-8",
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey:@"text/html",
(__bridge NSString *)kQLPreviewPropertyAttachmentsKey:@{
@"AUDIO":@{
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey:@"audio/mpeg",
(__bridge NSString *)kQLPreviewPropertyAttachmentDataKey: audioData,
},
},
};
[html appendString:@"<html>"];
[html appendString:@"<body>"];
[html appendString:@"<audio src=\"cid:AUDIO\" type=\"audio/mpeg\" controls=\"true\" autoplay=\"true\" />"];
[html appendString:@"</body>"];
[html appendString:@"</html>"];
QLPreviewRequestSetDataRepresentation(preview,(CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding],kUTTypeHTML,(CFDictionaryRef)props);
}
return noErr;
}
我认为你应该为此 report a bug to Apple!