6

I am trying to use Apple App Thinning feature (available from iOS 9) that let you differentiate resources based on device architecture and features. In my case what I would like to do is to have a different video file in the application bundle (in .mp4 format) one for the iPhone and one for the iPad using Xcode .xcassets Data Set.

To retrieve a file from a .xcassets Data Set Apple provides the NSDataAsset class, but: since AVPlayer needs a URL to play a video and NSDataAsset only provides its contents using Data format, I'm unable to play the video.

What I would like to do is to retrive the NSDataAsset .data URL. Is it possible?

Aluminum
  • 2,932
  • 5
  • 35
  • 63
  • 1
    You may look at https://stackoverflow.com/questions/23644193/can-i-create-an-nsurl-that-refers-to-in-memory-nsdata – notsoux Oct 19 '17 at 10:54

1 Answers1

-1

You can try:

NSDataAsset *videosDataAsset = [[NSDataAsset alloc] initWithName:@"AssetName"];
NSData *data = videosDataAsset.data;
NSString *filename = @"FileToSaveInto.mp4";
NSURL *URL = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:filename];

if ([data writeToURL:URL atomically:YES]) {
    // run player
}