public ActionResult ConfirmUpload(Videos video) { try { IVideosService videoSrv = IoC.Resolve <IVideosService>(); video.LinkType = LinkType.Local; video.CreatedBy = HttpContext.User.Identity.Name; video.VideoPath = "/VideosStore/video/" + video.VideoPath; //Hình ảnh video.URLName = FX.Utils.Common.TextHelper.ToUrlFriendly(video.NameVNI); ConvertVideo conv = new ConvertVideo(video.VideoPath); if (video.VideoPath.IndexOf("mp4") > 0) { Thread thread = new Thread(new ThreadStart(conv.ConvertVideoToWebM)); thread.Start(); } else if (video.VideoPath.IndexOf("webm") > 0) { Thread thread = new Thread(new ThreadStart(conv.ConvertVideoToMp4)); thread.Start(); } string videoFull = video.VideoPath.Split('/')[3]; string videoName = videoFull.Split('.')[0]; string imageName = "/UploadStore/Videos/" + videoName + ".jpg"; video.ImagePath = imageName; videoSrv.CreateNew(video); videoSrv.CommitChanges(); Messages.AddFlashMessage("Thêm mới thành công."); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Create", "Create Video Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(new JsonResult() { Data = "Tải Video thành công!" }); } catch (Exception ex) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Create", "Create Video Error : " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(new JsonResult() { Data = "Có lỗi xảy ra vui lòng thực hiện lại." }); } }
public ActionResult Create(Videos video) { try { IVideosService videoSrv = IoC.Resolve <IVideosService>(); video.CreatedBy = HttpContext.User.Identity.Name; video.ImagePath = "/UploadStore/Videos/video.jpg"; video.LinkType = LinkType.Youtube; //Kiểm tra video đường dẫn video chuẩn chưa . if (video.VideoPath.IndexOf("embed") <= 0) { string[] arr = video.VideoPath.Split('='); string yId = arr[1]; if (yId.Length > 0) { string convertToEmbedLink = "https://www.youtube.com/embed/" + yId; video.VideoPath = convertToEmbedLink; //Định dạng chuẩn để xem video = thẻ iframe WebClient cli = new WebClient(); var imgBytes = cli.DownloadData("http://img.youtube.com/vi/" + yId + "/0.jpg"); // System.IO.File.WriteAllBytes(ConfigurationSettings.AppSettings.Get("PhysicalSiteDataDirectory") + @"\_thumbs\Videos\" + yId + ".jpg", imgBytes); video.ImagePath = "/UploadStore/Videos/" + yId + ".jpg"; } } video.URLName = FX.Utils.Common.TextHelper.ToUrlFriendly(video.NameVNI); videoSrv.CreateNew(video); videoSrv.CommitChanges(); Messages.AddFlashMessage("Thêm mới thành công."); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Create", "Create Video Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(RedirectToAction("Index")); } catch (Exception ex) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Create", "Create Video Error : " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); IVideoTypeService videoTypeSrv = IoC.Resolve <IVideoTypeService>(); VideoModels model = new VideoModels(); model.Video = video; model.VideoTypes = videoTypeSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList(); return(View(model)); } }