private void ListViewUpdate(List <string> imageNames)//更新listview中的内容,listview中是已扫描过的视频 { imageList1.Images.Clear(); listView1.Clear(); int pic_size = 256; for (int i = imageNames.Count - 1; i >= 0; i--) { if (!File.Exists(imageNames[i])) { service.RemoveFlie(imageNames[i]); imageNames.Remove(imageNames[i]); continue; } Bitmap bm = WindowsThumbnailProvider.GetThumbnail(imageNames[i], pic_size, pic_size, ThumbnailOptions.None); Image img = Image.FromHbitmap(bm.GetHbitmap()); imageList1.Images.Add(img); } for (int i = imageNames.Count - 1; i >= 0; i--) { ListViewItem lvi = new ListViewItem(); lvi.ImageIndex = imageNames.Count - 1 - i; lvi.Name = imageNames[i]; lvi.Text = System.IO.Path.GetFileNameWithoutExtension(imageNames[i]); listView1.Items.Add(lvi); } listView1.EndUpdate(); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "mp4文件|*.mp4|mkv文件|*.mkv|avi文件|*。avi"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string url = openFileDialog1.FileName; axWindowsMediaPlayer1.URL = url; try { string fileName = System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName); currentMovie = new Video(fileName, openFileDialog1.FileName); if (!listBox1.Items.Contains(openFileDialog1.SafeFileName)) { Bitmap bm = WindowsThumbnailProvider.GetThumbnail(url, 256, 256, ThumbnailOptions.None); Image img = Image.FromHbitmap(bm.GetHbitmap()); imageList1.Images.Add(img); listBox1.Items.Add(fileName); movieList.Add(currentMovie); } axWindowsMediaPlayer1.Ctlcontrols.play(); } catch { MessageBox.Show("播放失败"); } } }
//---------------------------------------------------------------------------------- private void ListViewUpdate(List <string> imageNames)//更新listview中的内容 { imageList1.Images.Clear(); listView1.Clear(); int pgbSpeed = 0; if (imageNames.Count != 0) { progressBar1.Value = 0; progressBar1.Visible = true; pgbSpeed = 100 / imageNames.Count; } int pic_size = 256; for (int i = imageNames.Count - 1; i >= 0; i--) { if (!File.Exists(imageNames[i])) { service.RemoveFlie(imageNames[i]); imageNames.Remove(imageNames[i]); continue; } Bitmap bm = WindowsThumbnailProvider.GetThumbnail(imageNames[i], pic_size, pic_size, ThumbnailOptions.None); Image img = Image.FromHbitmap(bm.GetHbitmap()); imageList1.Images.Add(img); progressBar1.Value += pgbSpeed; } for (int i = imageNames.Count - 1; i >= 0; i--) { ListViewItem lvi = new ListViewItem(); lvi.ImageIndex = imageNames.Count - 1 - i; lvi.Name = imageNames[i]; lvi.Text = System.IO.Path.GetFileNameWithoutExtension(imageNames[i]); //string str = imageNames[i]; //string[] name = str.Split('\\'); //lvi.Text = name[name.Length - 1]; listView1.Items.Add(lvi); } progressBar1.Value = 100; progressBar1.Visible = false; progressBar1.Value = 0; listView1.EndUpdate(); }
//异步实现视频缩略图的获取和主界面listview的刷新 //-------------------------------------------------------------------------- public void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { //...执行线程任务 List <string> imageNames = service.GetAllVideos(); int pic_size = 256; for (int i = imageNames.Count - 1; i >= 0; i--) { if (!File.Exists(imageNames[i])) { service.RemoveFlie(imageNames[i]); imageNames.Remove(imageNames[i]); continue; } Bitmap bm = WindowsThumbnailProvider.GetThumbnail(imageNames[i], pic_size, pic_size, ThumbnailOptions.None); Image img = Image.FromHbitmap(bm.GetHbitmap()); //在线程中更新UI(通过ReportProgress方法) backgroundWorker1.ReportProgress((1 - i / imageNames.Count) * 100, img); } }
//更新listview中的内容,listview中是该列表的视频 private void ListViewUpdate(List <string> Videos) { imageList1.Images.Clear(); listView1.Clear(); List <string> BindedVideos = service.GetBindedVideos(ListID); List <string> ImageNames = new List <string>(); int pic_size = 256; for (int i = Videos.Count - 1; i >= 0; i--) { string imageName = Videos[i]; if (!File.Exists(imageName)) { service.RemoveFlie(imageName); Videos.Remove(imageName); continue; } Bitmap bm = WindowsThumbnailProvider.GetThumbnail(imageName, pic_size, pic_size, ThumbnailOptions.None); Image img = Image.FromHbitmap(bm.GetHbitmap()); imageList1.Images.Add(img); ImageNames.Add(imageName); if (BindedVideos.Contains(imageName)) { List <string> Document = service.GetFilesOfVideo(ListID, imageName); for (int j = Document.Count - 1; j >= 0; j--) { if (!File.Exists(Document[j])) { service.RemoveDocument(Document[j]); Document.Remove(Document[j]); continue; } string extension = Document[j].Substring(Document[j].LastIndexOf(".") + 1, Document[j].Length - Document[j].LastIndexOf(".") - 1); Image img1; switch (extension) { case "pdf": img1 = imageList2.Images[0]; imageList1.Images.Add(img1); break; case "ppt": img1 = imageList2.Images[1]; imageList1.Images.Add(img1); break; case "pptx": img1 = imageList2.Images[1]; imageList1.Images.Add(img1); break; case "doc": img1 = imageList2.Images[2]; imageList1.Images.Add(img1); break; case "docx": img1 = imageList2.Images[2]; imageList1.Images.Add(img1); break; } ImageNames.Add(Document[j]); } } } for (int i = 0; i < ImageNames.Count; i++) { ListViewItem lvi = new ListViewItem(); lvi.ImageIndex = i; lvi.Name = ImageNames[i]; lvi.Text = System.IO.Path.GetFileNameWithoutExtension(ImageNames[i]); listView1.Items.Add(lvi); } listView1.EndUpdate(); }