I'd like to use AVFoundation to display a video on osx. I would like to initialize the movie from raw data at runtime. According to this document: https://developer.apple.com/library/mac/#technotes/tn2300/_index.html AVAsset
is the equivalent of QTKit's QTMovie
. QTMovie
has the function movieWithData:error:
to load the video from data, while i could not find anything similar in AVAsset
. So, is it possible to do the same thing in AVFoundation at all?
Thank you
NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"tmp.mp3"];
NSFileManager *manager = [NSFileManager defaultManager];
[manager createFileAtPath:tempFilePath contents:mp3Data attributes:nil];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:tempFilePath] options:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[manager removeItemAtPath:tempFilePath error:nil];
});
I am afraid the unique possibility to initialize AVAsset
instance from raw data is to save the data before as a file. AVAsset
and its subclasses are using URLs only in their constructors.
It is possible to create an AVAsset
from an NSData
via an AVAssetResourceLoaderDelegate
implementation.
Specifically implement:
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool
It must:
loadingRequest.contentInformationRequest.contentType = AVFileType.mycontenttype.rawValue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With