星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Uc_VideoItem.xaml.cs 13KB

1 jaar geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. using Common.system;
  2. using System;
  3. using System.Diagnostics;
  4. using System.Windows;
  5. using System.Windows.Input;
  6. using XHWK.Model;
  7. using XHWK.WKTool.DAL;
  8. namespace XHWK.WKTool.UControl
  9. {
  10. using system;
  11. /// <summary>
  12. /// 视频信息
  13. /// </summary>
  14. public partial class UcVideoItem
  15. {
  16. #region 初始值
  17. /// <summary>
  18. /// 视频模型
  19. /// </summary>
  20. private ModelVideo _videoModel;
  21. /// <summary>
  22. /// 刷新视频列表
  23. /// </summary>
  24. public delegate void RefreshVideoList();
  25. /// <summary>
  26. /// 刷新视频列表事件
  27. /// </summary>
  28. public event RefreshVideoList ClickRefreshVideoList;
  29. /// <summary>
  30. /// 登录
  31. /// </summary>
  32. public delegate void UploadLogin();
  33. /// <summary>
  34. /// 登录事件
  35. /// </summary>
  36. public event UploadLogin ClickUploadLogin;
  37. /// <summary>
  38. /// 上传页面
  39. /// </summary>
  40. private UploadWindow _wUploadWindow;
  41. #endregion 初始值
  42. #region 初始化
  43. /// <summary>
  44. /// 视频信息
  45. /// </summary>
  46. /// <param name="modelVideo"></param>
  47. public UcVideoItem(ModelVideo modelVideo)
  48. {
  49. InitializeComponent();
  50. App.IsUpLoad = false;
  51. _videoModel = modelVideo;
  52. DataContext = App.PageContextData;
  53. if (FileToolsCommon.IsExistFile(_videoModel.ThumbnailPath))
  54. {
  55. ImgVideo.Source = ImageHelper.ReadBitmapImageFile(_videoModel.ThumbnailPath); // new BitmapImage(new Uri(VideoModel.ThumbnailPath));
  56. }
  57. string videoName = FileToolsCommon.GetIoFileNameNoExtension(_videoModel.VideoPath);
  58. TbName.Text = videoName.Length > 11 ? videoName.Substring(0, 11) + "..." : videoName;
  59. TbName.ToolTip = videoName;
  60. LblDateSize.Content = _videoModel.RSTime + " " + _videoModel.VideoSize;
  61. if (_videoModel.IsUpload)
  62. {
  63. BtnUpload.IsEnabled = false;
  64. BtnUpload.Background.Opacity = 0.6;
  65. }
  66. }
  67. #endregion 初始化
  68. #region 修改视频名
  69. /// <summary>
  70. /// 双击修改视频名
  71. /// </summary>
  72. /// <param name="sender"></param>
  73. /// <param name="e"></param>
  74. private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  75. {
  76. if (e.ClickCount == 2)
  77. {
  78. TxtModify.Text = TbName.ToolTip.ToString();
  79. TbName.Visibility = Visibility.Hidden;
  80. GridModify.Visibility = Visibility.Visible;
  81. }
  82. }
  83. /// <summary>
  84. /// 失去焦点保存视频名
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void TxtModify_LostFocus(object sender, RoutedEventArgs e)
  89. {
  90. ModifyVideoName();
  91. }
  92. /// <summary>
  93. /// Enter保存
  94. /// </summary>
  95. /// <param name="sender"></param>
  96. /// <param name="e"></param>
  97. private void TxtModify_KeyUp(object sender, KeyEventArgs e)
  98. {
  99. if (e.Key == System.Windows.Input.Key.Enter)
  100. {
  101. ModifyVideoName();
  102. }
  103. }
  104. /// <summary>
  105. /// 修改文件名保存
  106. /// </summary>
  107. /// <param name="sender"></param>
  108. /// <param name="e"></param>
  109. private void BtnNameModifyOK_Click(object sender, RoutedEventArgs e)
  110. {
  111. ModifyVideoName();
  112. }
  113. /// <summary>
  114. /// 修改视频文件名
  115. /// </summary>
  116. private void ModifyVideoName()
  117. {
  118. if (TxtModify.Text != TbName.Text)
  119. {
  120. if (ModifyPathName(_videoModel.FileGuid, TxtModify.Text + "." + _videoModel.VideoType, out string errMessage))
  121. {
  122. //保存成功
  123. TbName.Text = TxtModify.Text.Length > 11 ? TxtModify.Text.Substring(0, 11) + "..." : TxtModify.Text;
  124. TbName.ToolTip = TxtModify.Text;
  125. TbName.Visibility = Visibility.Visible;
  126. GridModify.Visibility = Visibility.Hidden;
  127. }
  128. else
  129. {
  130. MessageWindow.Show(errMessage);
  131. }
  132. }
  133. else
  134. {
  135. TbName.Visibility = Visibility.Visible;
  136. GridModify.Visibility = Visibility.Hidden;
  137. }
  138. }
  139. /// <summary>
  140. /// 修改视频文件名
  141. /// </summary>
  142. /// <param name="fileGuid"></param>
  143. /// <param name="newName">新文件名带后缀 不带路径</param>
  144. /// <param name="errmessage">错误信息</param>
  145. /// <returns></returns>
  146. private bool ModifyPathName(string fileGuid, string newName, out string errmessage)
  147. {
  148. errmessage = "";
  149. foreach (ModelWkData wkData in App.WKDataList)
  150. {
  151. if (wkData.VideoList.Exists(x => x.FileGuid == fileGuid))
  152. {
  153. ModelVideo modelVideo = wkData.VideoList.Find(x => x.FileGuid == fileGuid);
  154. string filePathName = modelVideo.VideoPath;
  155. string filePath = FileToolsCommon.GetDirectoryName(filePathName);
  156. string newFilePathName = filePath + newName;
  157. //缩略图
  158. string thumbnailPath = filePath + "ThumbnailPath/";
  159. FileToolsCommon.CreateDirectory(thumbnailPath);
  160. //缩略图存储位置
  161. string thumbnailPathName = thumbnailPath + newName.Replace(".", "") + ".JPG";
  162. if (FileToolsCommon.IsExistFile(newFilePathName))
  163. {
  164. errmessage = "文件已存在,请重新修改文件名!";
  165. return false;
  166. }
  167. //修改文件名
  168. FileToolsCommon.Copy(filePathName, newFilePathName);
  169. modelVideo.VideoPath = newFilePathName;
  170. //修改缩略图名
  171. FileToolsCommon.DeleteFile(thumbnailPathName);
  172. FileToolsCommon.Copy(modelVideo.ThumbnailPath, thumbnailPathName);
  173. modelVideo.ThumbnailPath = thumbnailPathName;
  174. App.SaveWkData();
  175. return true;
  176. }
  177. }
  178. errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
  179. return false;
  180. }
  181. #endregion 修改视频名
  182. #region 删除视频
  183. /// <summary>
  184. /// 删除视频
  185. /// </summary>
  186. /// <param name="sender"></param>
  187. /// <param name="e"></param>
  188. private void BtnDelVideo_Click(object sender, RoutedEventArgs e)
  189. {
  190. MessageBoxResult dr = MessageWindow.Show("确定删除该视频?", "提示", MessageBoxButton.OKCancel);
  191. if (dr == MessageBoxResult.OK)
  192. {
  193. foreach (ModelWkData wKData in App.WKDataList)
  194. {
  195. if (wKData.VideoList == null)
  196. {
  197. continue;
  198. }
  199. if (wKData.VideoList.Exists(x => x.FileGuid == _videoModel.FileGuid))
  200. {
  201. try
  202. {
  203. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid).VideoPath);
  204. string thumbnailPath = wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid).ThumbnailPath;
  205. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid));
  206. //初始化页面 刷新视频列表
  207. if (ClickRefreshVideoList != null)
  208. {
  209. ClickRefreshVideoList();
  210. }
  211. ImgVideo.Source = null;
  212. GC.Collect();
  213. FileToolsCommon.DeleteFile(thumbnailPath);
  214. Visibility = Visibility.Hidden;
  215. return;
  216. }
  217. catch (Exception ex)
  218. {
  219. MessageWindow.Show("无法删除视频!" + ex.Message);
  220. return;
  221. }
  222. }
  223. }
  224. }
  225. }
  226. #endregion 删除视频
  227. #region 播放视频
  228. private void BtnVideoPlay_Click(object sender, RoutedEventArgs e)
  229. {
  230. try
  231. {
  232. ProcessStartInfo psi = new ProcessStartInfo(_videoModel.VideoPath);
  233. Process pro = new Process
  234. {
  235. StartInfo = psi
  236. };
  237. pro.Start();
  238. }
  239. catch (Exception ex)
  240. {
  241. LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
  242. System.Windows.MessageBox.Show(ex.Message);
  243. }
  244. }
  245. /// <summary>
  246. /// 视频播放
  247. /// </summary>
  248. /// <param name="sender"></param>
  249. /// <param name="e"></param>
  250. private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  251. {
  252. try
  253. {
  254. ProcessStartInfo psi = new ProcessStartInfo(_videoModel.VideoPath);
  255. Process pro = new Process
  256. {
  257. StartInfo = psi
  258. };
  259. pro.Start();
  260. }
  261. catch (Exception ex)
  262. {
  263. LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
  264. System.Windows.MessageBox.Show(ex.Message);
  265. }
  266. }
  267. #endregion 播放视频
  268. /// <summary>
  269. /// 视频上传
  270. /// </summary>
  271. /// <param name="sender"></param>
  272. /// <param name="e"></param>
  273. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  274. {
  275. if (App.IsLoginType == false)
  276. {
  277. //登录
  278. if (ClickUploadLogin != null)
  279. {
  280. ClickUploadLogin();
  281. }
  282. if (App.IsLoginType == false)
  283. {
  284. return;
  285. }
  286. }
  287. if (!App.IsUpLoad)
  288. {
  289. App.IsUpLoad = true;
  290. DalUpload dAlUpload = new DalUpload();
  291. if (dAlUpload.UploadVideo(_videoModel.FileGuid, out string errMessage))
  292. {
  293. App.IsUpLoad = false;
  294. //MessageWindow.Show("视频上传服务器成功!");
  295. if (_wUploadWindow == null)
  296. {
  297. _wUploadWindow = new UploadWindow { Owner = App.W_XHMicroLessonSystemWindow };
  298. _wUploadWindow.ChangeTextEvents += frm_ChangeTextEvents;
  299. }
  300. //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
  301. _wUploadWindow.Initialize(
  302. TbName.Text,
  303. _videoModel.VideoSizebyte,
  304. _videoModel.VideoType.ToString(),
  305. _videoModel.FileGuid,
  306. 0
  307. );
  308. }
  309. else
  310. {
  311. App.IsUpLoad = false;
  312. MessageWindow.Show(errMessage);
  313. }
  314. }
  315. }
  316. /// <summary>
  317. /// 上传返回事件
  318. /// </summary>
  319. /// <param name="text"></param>
  320. /// <param name="i"></param>
  321. private void frm_ChangeTextEvents(string text, int i)
  322. {
  323. if ("上传成功".Equals(text))
  324. {
  325. _wUploadWindow.Close();
  326. BtnUpload.IsEnabled = false;
  327. BtnUpload.Background.Opacity = 0.6;
  328. }
  329. }
  330. /// <summary>
  331. /// 编辑
  332. /// </summary>
  333. /// <param name="sender"></param>
  334. /// <param name="e"></param>
  335. private void Button_Click(object sender, RoutedEventArgs e)
  336. {
  337. if (App.W_VideoClipWindow == null)
  338. {
  339. App.W_VideoClipWindow = new VideoClipWindow();
  340. }
  341. if (App.W_VideoClipWindow.InitClipVideo(_videoModel.VideoPath))
  342. {
  343. App.W_VideoClipWindow.ShowDialog();
  344. }
  345. }
  346. }
  347. }