How to convert Nsdata to URL

Asked

Viewed 60 times

0

Friends I have an image recorded on Sqlite, read the image and put in a Nsdata variable

Now I need to play 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;

Thank you,

  • 1

    You are trying to show an image on a video player?

  • Simply save Nsdata to disk using the Nsfilemanager writeToURL method and use this url

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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.