private void dSkinButton1_Click(object sender, EventArgs e) { if (vlcControl1.GetCurrentMedia() == null) { ChatHistoryListItem item = imageList[ShowIndex]; if (!File.Exists(item.model.fileLocalPath)) { MessageBox.Show("视频下载中"); return; } else { this.BeginInvoke(new EventHandler((s, ee) => { vlcControl1.Play(new FileStream(item.model.fileLocalPath, FileMode.Open)); })); } } else { if (vlcControl1.IsPlaying) { vlcControl1.BeginInvoke(new EventHandler((ss, ee) => { vlcControl1.Pause(); })); } else { if (isPaused) { isPaused = false; vlcControl1.BeginInvoke(new EventHandler((ss, ee) => { vlcControl1.Play(); })); } else { ChatHistoryListItem item = imageList[ShowIndex]; if (File.Exists(item.model.fileLocalPath)) { this.BeginInvoke(new EventHandler((s, eee) => { vlcControl1.Play(new FileStream(item.model.fileLocalPath, FileMode.Open)); })); } else { DownLoadChatFileManager.shard.downloadFileAttchment(item.model.message, (msg) => { EMVideoMessageBody body = msg.bodies()[0] as EMVideoMessageBody; if (body != null) { item.model.fileLocalPath = body.localPath(); if (File.Exists(item.model.fileLocalPath)) { this.BeginInvoke(new EventHandler((s, eee) => { vlcControl1.Play(new FileStream(item.model.fileLocalPath, FileMode.Open)); })); } else { MessageBox.Show("下载失败"); } } }); } } } } }
private void showImage(int index) { if (index >= imageList.Count) { return; } ShowIndex = index; this.BeginInvoke(new EventHandler((s, e) => { if (ShowIndex == 0) { leftPictureBox.Visible = false; } else { leftPictureBox.Visible = true; } if (ShowIndex == imageList.Count - 1) { rightPictureBox2.Visible = false; } else { rightPictureBox2.Visible = true; } this.Invalidate(); })); ChatHistoryListItem item = imageList[ShowIndex]; if (item.model.isGifFace) { if (item.model.faceH < Height - 60 && item.model.faceW < Width - 150) { this.BeginInvoke(new EventHandler((s, e) => { if (vlcControl1.IsPlaying) { vlcControl1.Stop(); } vlcControl1.Visible = false; dSkinPictureBox1.Visible = true; dSkinNewPanel1.Visible = false; dSkinButton1.Visible = false; dSkinPictureBox1.Image = item.model.image == null ? item.model.thumbnailImage : item.model.image; dSkinPictureBox1.Location = new Point((Width - item.model.faceW - 150) / 2, (Height - item.model.faceH) / 2 + 60); dSkinPictureBox1.Size = new Size(item.model.faceW, item.model.faceH); DCWebImageMaanager.shard.downloadImageAsync(item.model.gitFaceURL, (image, b) => { if (image != null) { if (dSkinPictureBox1.IsHandleCreated) { dSkinPictureBox1.BeginInvoke(new EventHandler((ss, ee) => { dSkinPictureBox1.Image = image; dSkinPictureBox1.Invalidate(); })); } } }); this.Invalidate(); })); } else if (item.model.faceH > Height - 60) { int w = Convert.ToInt32((double)item.model.faceW / (double)item.model.faceH * (Height - 60)); this.BeginInvoke(new EventHandler((s, e) => { if (vlcControl1.IsPlaying) { vlcControl1.Stop(); } vlcControl1.Visible = false; dSkinPictureBox1.Visible = true; dSkinNewPanel1.Visible = false; dSkinButton1.Visible = false; dSkinPictureBox1.Image = item.model.image == null ? item.model.thumbnailImage : item.model.image; dSkinPictureBox1.Location = new Point((Width - 150 - w) / 2, 60); dSkinPictureBox1.Size = new Size(w, Height - 60); DCWebImageMaanager.shard.downloadImageAsync(item.model.gitFaceURL, (image, b) => { if (image != null) { if (dSkinPictureBox1.IsHandleCreated) { dSkinPictureBox1.BeginInvoke(new EventHandler((ss, ee) => { dSkinPictureBox1.Image = image; dSkinPictureBox1.Invalidate(); })); } } }); this.Invalidate(); })); } else { int h = Convert.ToInt32((double)item.model.faceH / (double)item.model.faceW * ((double)Width - 150)); this.BeginInvoke(new EventHandler((s, e) => { if (vlcControl1.IsPlaying) { vlcControl1.Stop(); } vlcControl1.Visible = false; dSkinPictureBox1.Visible = true; dSkinNewPanel1.Visible = false; dSkinButton1.Visible = false; dSkinPictureBox1.Image = item.model.image == null ? item.model.thumbnailImage : item.model.image; dSkinPictureBox1.Location = new Point((Width - 150 - item.model.faceW) / 2, (Height - h) / 2 + 60); dSkinPictureBox1.Size = new Size(item.model.faceW, h); DCWebImageMaanager.shard.downloadImageAsync(item.model.gitFaceURL, (image, b) => { if (image != null) { if (dSkinPictureBox1.IsHandleCreated) { dSkinPictureBox1.BeginInvoke(new EventHandler((ss, ee) => { dSkinPictureBox1.Image = image; dSkinPictureBox1.Invalidate(); })); } } }); this.Invalidate(); })); } } else if (item.model.bodyType == EMMessageBodyType.IMAGE) { if (File.Exists(item.model.fileLocalPath)) { try { Image image = Image.FromFile(item.model.fileLocalPath); Size s = image.Size; if (s.Height > s.Width) { int w = Convert.ToInt32((double)s.Width / (double)s.Height * (this.Height - 60)); int h = Convert.ToInt32((double)s.Height / (double)s.Width * w); s = new Size(w, h); } else { int h = Convert.ToInt32((double)s.Height / (double)s.Width * (this.Width - 150)); int w = Convert.ToInt32((double)s.Width / (double)s.Height * h); s = new Size(w, h); } this.BeginInvoke(new EventHandler((ss, ee) => { if (vlcControl1.IsPlaying) { vlcControl1.Stop(); } vlcControl1.Visible = false; dSkinPictureBox1.Visible = true; dSkinNewPanel1.Visible = false; dSkinPictureBox1.Image = image; dSkinButton1.Visible = false; dSkinPictureBox1.Location = new Point((this.Width - 150 - s.Width) / 2 + 75, (this.Height - s.Height) / 2 + 60); dSkinPictureBox1.Size = s; this.Invalidate(); })); } catch (Exception e) { DownLoadChatFileManager.shard.downloadFileAttchment(item.model.message, (msg) => { EMImageMessageBody mImageMessageBody = msg.bodies()[0] as EMImageMessageBody; if (File.Exists(mImageMessageBody.localPath())) { Image image = Image.FromFile(mImageMessageBody.localPath()); if (image != null) { Size s = image.Size; if (s.Height > s.Width) { int w = Convert.ToInt32((double)s.Width / (double)s.Height * (this.Height - 60)); int h = Convert.ToInt32((double)s.Height / (double)s.Width * w); s = new Size(w, h); } else { int h = Convert.ToInt32((double)s.Height / (double)s.Width * (this.Width - 150)); int w = Convert.ToInt32((double)s.Width / (double)s.Height * h); s = new Size(w, h); } this.BeginInvoke(new EventHandler((ss, ee) => { if (vlcControl1.IsPlaying) { vlcControl1.Stop(); } vlcControl1.Visible = false; dSkinPictureBox1.Visible = true; dSkinNewPanel1.Visible = false; dSkinButton1.Visible = false; dSkinPictureBox1.Image = image; dSkinPictureBox1.Location = new Point((this.Width - 150 - s.Width) / 2 + 75, (this.Height - s.Height) / 2 + 60); dSkinPictureBox1.Size = s; this.Invalidate(); })); } else { MessageBox.Show("加载图片失败"); } } }); } } else { DownLoadChatFileManager.shard.downloadFileAttchment(item.model.message, (msg) => { EMImageMessageBody mImageMessageBody = msg.bodies()[0] as EMImageMessageBody; if (File.Exists(mImageMessageBody.localPath())) { Image image = Image.FromFile(mImageMessageBody.localPath()); if (image != null) { Size s = image.Size; if (s.Height > s.Width) { int w = Convert.ToInt32((double)s.Width / (double)s.Height * (this.Height - 60)); int h = Convert.ToInt32((double)s.Height / (double)s.Width * w); s = new Size(w, h); } else { int h = Convert.ToInt32((double)s.Height / (double)s.Width * (this.Width - 150)); int w = Convert.ToInt32((double)s.Width / (double)s.Height * h); s = new Size(w, h); } this.BeginInvoke(new EventHandler((ss, ee) => { if (vlcControl1.IsPlaying) { vlcControl1.Stop(); } vlcControl1.Visible = false; dSkinPictureBox1.Visible = true; dSkinNewPanel1.Visible = false; dSkinButton1.Visible = false; dSkinPictureBox1.Image = image; dSkinPictureBox1.Location = new Point((this.Width - 150 - s.Width) / 2, (this.Height - s.Height) / 2 + 60); dSkinPictureBox1.Size = s; this.Invalidate(); })); } else { MessageBox.Show("加载图片失败"); } } }); } } else if (item.model.bodyType == EMMessageBodyType.VIDEO) { this.BeginInvoke(new EventHandler((s, e) => { controlHost1.Location = new Point(75, 60); controlHost1.Size = new Size(Width - 150, Height - 60); dSkinNewPanel1.Visible = true; dSkinPictureBox1.Visible = false; dSkinButton1.Visible = true; dSkinNewPanel1.Location = new Point((controlHost1.Width - 200) / 2, controlHost1.Height - 100); this.Invalidate(); })); if (File.Exists(item.model.fileLocalPath)) { this.BeginInvoke(new EventHandler((s, e) => { vlcControl1.Play(new FileStream(item.model.fileLocalPath, FileMode.Open)); })); } else { DownLoadChatFileManager.shard.downloadFileAttchment(item.model.message, (msg) => { EMVideoMessageBody body = msg.bodies()[0] as EMVideoMessageBody; if (body != null) { item.model.fileLocalPath = body.localPath(); if (File.Exists(item.model.fileLocalPath)) { this.BeginInvoke(new EventHandler((s, e) => { vlcControl1.Play(new FileStream(item.model.fileLocalPath, FileMode.Open)); })); } else { MessageBox.Show("下载失败"); } } }); } } }
public MessageModel(EMMessage mMessage) { this.message = mMessage; if (message.bodies().Length < 1) { return; } bodyType = message.bodies()[0].type; chatType = message.chatType(); messageId = message.msgId(); firstbody = message.bodies()[0]; isRead = message.isRead(); if (message.msgDirection() == EMMessageDirection.SEND) { isSender = true; } else { isSender = false; } nickName = message.from(); if (bodyType == EMMessageBodyType.TEXT) { if (message.getAttribute("jpzim_is_big_expression", out isGifFace)) { if (isGifFace) { message.getAttribute("jpzim_big_expression_path", out gitFaceURL); message.getAttribute("faceH", out faceH); message.getAttribute("faceW", out faceW); if (!string.IsNullOrEmpty(gitFaceURL)) { DCWebImageMaanager.shard.downloadImageAsync(gitFaceURL, (image, b) => { this.image = image; if (faceH < 1 || faceW < 1) { faceW = image.Width; faceH = image.Height; } }); } text = "[动画表情]"; isRead = message.isRead(); setupUserInfo(); return; } } string typ; if (message.getAttribute("type", out typ)) { if (typ.Equals("person")) { isIDCard = true; isRead = message.isRead(); message.getAttribute("id", out IDCardID); return; } } EMTextMessageBody body = (EMTextMessageBody)message.bodies()[0]; text = body.text(); isRead = message.isRead(); if (text.EndsWith("_encode")) { var arr = text.Split('_'); text = DCEncrypt.Decrypt(arr[0], DCEncrypt.key); if (string.IsNullOrEmpty(text)) { text = body.text(); } } } else if (bodyType == EMMessageBodyType.IMAGE) { EMImageMessageBody body = (EMImageMessageBody)message.bodies()[0]; var file = body.localPath(); if (!string.IsNullOrEmpty(body.localPath()) && File.Exists(body.localPath())) { image = new Bitmap(body.localPath()); } fileLocalPath = body.localPath(); thumbnailFileLocalPath = body.thumbnailLocalPath(); fileURLPath = body.remotePath(); thumbnailFileURLPath = body.thumbnailRemotePath(); fileSize = body.fileLength(); imageSize = new Size(Convert.ToInt32(body.size().mWidth), Convert.ToInt32(body.size().mHeight)); thumbnailImageSize = new Size(Convert.ToInt32(body.thumbnailSize().mWidth), Convert.ToInt32(body.thumbnailSize().mWidth)); } else if (bodyType == EMMessageBodyType.VOICE) { EMVoiceMessageBody body = (EMVoiceMessageBody)message.bodies()[0]; fileLocalPath = body.localPath(); fileURLPath = body.remotePath(); fileSize = body.fileLength(); mediaDuration = body.duration(); } else if (bodyType == EMMessageBodyType.VIDEO) { EMVideoMessageBody body = (EMVideoMessageBody)message.bodies()[0]; fileLocalPath = body.localPath(); thumbnailFileLocalPath = body.thumbnailLocalPath(); fileURLPath = body.remotePath(); thumbnailFileURLPath = body.thumbnailRemotePath(); fileSize = body.fileLength(); if (string.IsNullOrEmpty(thumbnailFileLocalPath) && File.Exists(body.thumbnailLocalPath())) { thumbnailImage = Image.FromFile(thumbnailFileLocalPath); } thumbnailImageSize = new Size(Convert.ToInt32(body.size().mWidth), Convert.ToInt32(body.size().mHeight)); } else { if (bodyType == EMMessageBodyType.COMMAND) { return; } if (bodyType == EMMessageBodyType.LOCATION) { EMLocationMessageBody body1 = firstbody as EMLocationMessageBody; latitude = body1.latitude(); longitude = body1.longitude(); address = body1.address(); return; } EMFileMessageBody body = (EMFileMessageBody)message.bodies()[0]; fileLocalPath = body.localPath(); fileURLPath = body.remotePath(); fileSize = body.fileLength(); displayName = body.displayName(); fileSizeDes = getFileSize(); } isRead = message.isRead(); setupUserInfo(); }