I'm basing this answer on my personal experience.
With Xcode 4.2 on OSX 10.6.8 it was possible to load an audio file inside a HTML-based QuickLook plugin simply using the <src>
attribute of the <audio>
tag:
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;
}
Now, with Xcode 5.1 on Mavericks, it seems that neither using the cid:
scheme (I'll post an example below) does the job:
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;
}
I recon that you should report a bug to Apple for that!