Pergunta

I am writing a Quick Look plugin that can generate previews for some audio files like ogg and flac by converting them to AIFF with ffmpeg and then returning a minimalistic webpage with a <video> tag that references the converted AIFF file.

Everything runs well, except that I need to create those temporary AIFF files in the temporary folder. I've been looking for a way to get a callback when the user dismisses the Quick Look window to be able to delete my AIFF files, but I can't find one.

Is there a good way for me to delete those temporary files generated by my Quick Look plugin?

Foi útil?

Solução

I just spent a bit trying to resolve this myself for a similar issue trying to create a plugin to read various unsupported image formats. As far as I can tell, you can't really get a callback telling you when the view closes, since you hand the data off to Quick Look, so you can't really delete them later. If possible, try to convert it to an NSData object and then encode this in the HTML. The example is available as Dynamically Generating Previews > Generating Enriched HTML. For your case, you just need to replace the section:

[html appendString:@"<img src=\"cid:tabs.png\"><br>"];

With your tag. The cid: URL is the important call for accessing the temporary data. In your case, it would be something like:

[html appendString:@"<audio src=\"cid:converted.aiff\" controls autoplay><br>"];

And then set:

NSMutableDictionary *audioProps = [[NSMutableDictionary alloc] init];
[audioProps setObject:@"audio/aiff" forKey:(NSString *)kQLPreviewPropertyMIMETypeKey];
[audioProps setObject:audioData forKey:(NSString *)kQLPreviewPropertyAttachmentDataKey];
[props setObject:[NSDictionary dictionaryWithObject:audioProps forKey:@"converted.aiff"] forKey:(NSString *)kQLPreviewPropertyAttachmentsKey];

Where props is the main property reference, audioData is the NSData representing your aiff file, etc. If you have data in tmp from other processing, once you load the data into memory using NSData, you should delete the tmp file (see NSData dataWithContentsOfFile:).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top