I have an application in which there is button named video. When a user clicks on the button a new view opens which consists of 4 other buttons namely take video and browse for video.
When he clicks on take video the camera opens which allows him to take video and the video gets inserted on the view. This all has been done, but there is a problem when the user has taken the video and the video gets inserted on the view. There is a button on the view named add which allows to insert the video into the SQLite database.
I am having a problem on how to bind a video and how to insert the captured video into SQLite database.
Trying to put Roberto's suggestion in code:
1) generate a unique Id (generated by time stamp/ hash / CFUUIDCreate ...) .
CFStringRef uStr = CFUUIDCreateString(kCFAllocatorDefault,CFUUIDCreate(kCFAllocatorDefault));
NSString *uniqueId = [[NSString alloc] initWithString:uStr];
2) save the file in with this unique name. Now save the uniqueId
in SQLite DB.
NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [docsDir sstringByAppendingPathComponent:uniqueId];
NSFileManager *fManager = [NSFileManager defaultManager];
if (![fManager fileExistsAtPath:fileDirPath])
{
// save the file
}
3) In order to get the video, from the uniqueId
, try to construct the file path from it as,
NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [docsDir sstringByAppendingPathComponent:uniqueId];
NSFileManager *fManager = [NSFileManager defaultManager];
if ([fManager fileExistsAtPath:fileDirPath])
{
// access the file
}
I am not sure why you want to save binary data contains captured videos into database. In DB best practice, this is not good idea. I would suggest to save your videos into home folder directory and named the videos into something that you can bind into the database.
For example, user recorded a new video, in database you make a new record and you got generated id, let say ID 10, so you should save the video into home directory like 10.mp4
Hence, you can retreive your video later on based on the same ID value.
:)