         
         let videoURL = getDocumentUrl(videoName)
         let creationDate = selectedAsset?.creationDate
+        let assetId = selectedAsset?.localIdentifier
+        
         selectedAsset = nil
         do {
             try filemgr.copyItemAtURL(avUrlAsset.URL, toURL: videoURL)

        
        let object = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext)
        
        object.setValue(videoURL.lastPathComponent, forKey: "videoFile")
        object.setValue(thumbnailURL.lastPathComponent, forKey: "thumbFile")
        object.setValue(NSDate(), forKey: "openDate")

        
        selectedAsset = asset
        
        if let assetId = selectedAsset?.localIdentifier {
            
            let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
            let managedContext = appDelegate.managedObjectContext
            let fetchRequest = NSFetchRequest(entityName: "Video")
            fetchRequest.predicate = NSPredicate(format: "assetId == %@", assetId)
            
            do {
                let result = try managedContext.executeFetchRequest(fetchRequest) as! [NSManagedObject]
                if (result.count == 1) {
                    let object = result[0]
                    object.setValue(NSDate(), forKey: "openDate")
                    try managedContext.save()
                    dispatch_async(dispatch_get_main_queue()) {
                        self.loadVideos()
                        let video = Video(fromObject: object)
                        self.viewVideo(video)
                    }
                    return
                }
            } catch {
                fatalError("Failed to fetch video: \(error)")
            }
        }
        
        PHImageManager().requestAVAssetForVideo(
            asset, options:
            videoRequestOptions,
