After I export an AVMutableComposition
I use PHPhotoLibrary
to save the video to the camera roll. In the creationRequestForAssetFromVideoAtFileURL:
completion handler, I then open the saved video in Instagram, like so:
__block PHObjectPlaceholder *videoAssetPlaceholder;
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *req = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:localVideoURL];
videoAssetPlaceholder = req.placeholderForCreatedAsset;
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
completion(YES);
NSString *localID = videoAssetPlaceholder.localIdentifier;
NSRange rangeOfSlash = [localID rangeOfString:@"/"];
if (rangeOfSlash.location != NSNotFound) {
NSString *assetID = [localID substringToIndex:rangeOfSlash.location];
NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@", assetID]];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
}
}
}];
About 50% of the times Instagram opens and the video plays like expected. The other 50% of the times, however, both the video and the preview is white, and all I get is the sound. This usually gets fixed by selecting another video and then going back to my video. The video plays perfectly in the camera roll, it's only Instagram that causes problems. Is this an issue that Instagram has or could I be exporting my videos the wrong way?
These are my AVAssetExportSession
settings:
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition
presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL = url;
exporter.outputFileType = AVFileTypeMPEG4;
exporter.shouldOptimizeForNetworkUse = YES;
exporter.videoComposition = mainCompositionInst;
[exporter exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
handler(exporter.outputURL);
});
}];
Just heard from Apple DTS. They also agree this points to an Apple iOS bug and asked me to log it.
I cut out usage of AVAssetExportSession
like mentioned above and it solved my problem as a work around. So the issue seems to be around that method which is probably contained in the Instagram method you are using.
So until Apple fixes this or Instagram builds a work around, there does not seem to be a solution for this problem... Bummer
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