Play a video stored using NSDataAsset (Xcode xcassets)
Asked Answered
M

1

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?

Menzies answered 19/10, 2017 at 8:51 Comment(1)
You may look at #23644693Hal
U
-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
}
Underwear answered 14/12, 2017 at 6:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.