星火微课系统客户端
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

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