How to convert NSData to URL

0

Friends I have an image saved in SQLite, I have read the image and put it in an NSData variable

I now need to give play in this NSData but the component expects a URL

 NSURL *urlVideoFile = [NSURL fileURLWithPath:stringVideoPath];
//NSAssert(urlVideoFile, @"Expected not nil video url");

_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.player = [AVPlayer playerWithURL:**urlVideoFile**];

_playerViewController.view.frame = self.view.bounds;
_playerViewController.showsPlaybackControls = YES;

[self.view addSubview:_playerViewController.view];
self.view.autoresizesSubviews = YES;

Thanks,

    
asked by anonymous 15.09.2016 / 22:31

1 answer

1

[R E S O L V I D O]

NSString *docsDir;
NSArray *dirPaths;

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:@"teste.mp4"]];
[data writeToFile:databasePath atomically:YES];


 NSURL *urlVideoFile = [NSURL fileURLWithPath:databasePath];

_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.player = [AVPlayer playerWithURL:urlVideoFile];

_playerViewController.view.frame = self.view.bounds;
_playerViewController.showsPlaybackControls = YES;

[self.view addSubview:_playerViewController.view];
self.view.autoresizesSubviews = YES;
    
16.09.2016 / 16:13