using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PaintDotNet.ImageCollect
{
public class CameraVideoPlay : Form
{
//播放状态
private const int VLC_STOP = 1;
private const int VLC_PLAY = 2;
private const int VLC_PAUSE = 3;
private int m_stat;
VLCPlayer vlc_player;
public string videoPath = "";
public CameraVideoPlay()
{
InitializeComponent();
InitializeLanguageText();
}
private void CameraVideoPlay_Load(object sender, EventArgs e)
{
IntPtr render_wnd = this.panel1.Handle;
vlc_player = new VLCPlayer(render_wnd);
tbVideoTime.Text = "00:00 000/00:00 000";
m_stat = VLC_STOP;
vlc_player.playLocalVideo(videoPath);
vlc_player.SetPlayTime(0);
vlc_player.Stop();
trackBar1.SetRange(0, (int)(vlc_player.Duration / 100));
trackBar1.Value = 0;
tbVideoTime.Text = string.Format("{0}/{1}", GetTimeString(trackBar1.Value), GetTimeString(trackBar1.Maximum));
}
public double GetPlayTime()
{
return vlc_player.GetPlayTime();
}
private void btnStart_Click(object sender, EventArgs e)
{
if (m_stat == VLC_STOP)
{
trackBar1.SetRange(0, (int)(vlc_player.Duration / 100));
trackBar1.Value = 0;
vlc_player.playLocalVideo(videoPath);
vlc_player.SetPlayTime(0);
vlc_player.Play();
timer1.Start();
m_stat = VLC_PLAY;
}
else if (m_stat == VLC_PLAY)
{
vlc_player.Pause();
timer1.Stop();
m_stat = VLC_PAUSE;
}
else if (m_stat == VLC_PAUSE)
{
vlc_player.Play();
timer1.Start();
m_stat = VLC_PLAY;
}
updateUI();
}
private void btnReset_Click(object sender, EventArgs e)
{
vlc_player.Stop();
m_stat = VLC_STOP;
updateUI();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (m_stat == VLC_PLAY)
{
if (trackBar1.Value == trackBar1.Maximum)
{
vlc_player.Stop();
timer1.Stop();
m_stat = VLC_STOP;
}
else
{
trackBar1.Value = trackBar1.Value + 1;
tbVideoTime.Text = string.Format("{0}/{1}",
GetTimeString(trackBar1.Value),
GetTimeString(trackBar1.Maximum));
}
}
updateUI();
}
private string GetTimeString(int val)
{
val = val * 100;
int msec = val % 1000;
int minute = val / 1000 / 60;
int second = val / 1000 % 60;
return string.Format("{0:00}:{1:00} {2:000}", minute, second, msec);
}
private void updateUI()
{
if (m_stat == VLC_PLAY)
{
btnStart.Enabled = true;
btnReset.Enabled = true;
btnStart.Text = PdnResources.GetString("Menu.suspended.Text");
}
else
{
btnStart.Enabled = true;
btnReset.Enabled = false;
btnStart.Text = PdnResources.GetString("Menu.imagecapture.Videorecording.Play.text");
}
}
private string convertToTimeString(long time)
{
string ms = (time % 1000).ToString();
if (ms.Length < 2)
{
ms = "00" + ms;
}
else
{
ms = "0" + ms;
}
string mm = (time / 1000 / 60).ToString();
if (mm.Length < 2)
{
mm = "0" + mm;
}
string ss = ((time / 1000) % 60).ToString();
if (ss.Length < 2)
{
ss = "0" + ss;
}
return mm + ":" + ss + " " + ms;
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
vlc_player.SetPlayTime(trackBar1.Value);
//trackBar1.Value = (int)vlc_player.GetPlayTimeMSec()/100;
}
private void CameraVideoPlay_FormClosing(object sender, FormClosingEventArgs e)
{
if (m_stat != VLC_STOP)
{
timer1.Stop();
}
timer1 = null;
vlc_player.release();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
#region 控件
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
// Windows Form Designer generated code
private void InitializeLanguageText()
{
this.btnReset.Text = PdnResources.GetString("Menu.stop.text");
this.btnStart.Text = PdnResources.GetString("Menu.imagecapture.Videorecording.Play.text");
this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text");
this.Text = PdnResources.GetString("Menu.imagecapture.Videorecording.Play.text");
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.panel2 = new System.Windows.Forms.Panel();
this.tbVideoTime = new System.Windows.Forms.TextBox();
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.btnReset = new System.Windows.Forms.Button();
this.btnStart = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.btnClose = new System.Windows.Forms.Button();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
this.SuspendLayout();
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// panel2
//
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel2.Controls.Add(this.btnClose);
this.panel2.Controls.Add(this.tbVideoTime);
this.panel2.Controls.Add(this.trackBar1);
this.panel2.Controls.Add(this.btnReset);
this.panel2.Controls.Add(this.btnStart);
this.panel2.Location = new System.Drawing.Point(10, 518);
this.panel2.Margin = new System.Windows.Forms.Padding(4);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(650, 86);
this.panel2.TabIndex = 3;
//
// tbVideoTime
//
this.tbVideoTime.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.tbVideoTime.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.tbVideoTime.Location = new System.Drawing.Point(488, 8);
this.tbVideoTime.Margin = new System.Windows.Forms.Padding(4);
this.tbVideoTime.Name = "tbVideoTime";
this.tbVideoTime.ReadOnly = true;
this.tbVideoTime.Size = new System.Drawing.Size(162, 18);
this.tbVideoTime.TabIndex = 6;
this.tbVideoTime.Text = "00:00 000/00:00 000";
//
// trackBar1
//
this.trackBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.trackBar1.AutoSize = false;
this.trackBar1.Location = new System.Drawing.Point(11, 4);
this.trackBar1.Margin = new System.Windows.Forms.Padding(4);
this.trackBar1.Maximum = 999999999;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(476, 31);
this.trackBar1.TabIndex = 3;
this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
//
// btnReset
//
this.btnReset.Enabled = false;
this.btnReset.Location = new System.Drawing.Point(118, 34);
this.btnReset.Margin = new System.Windows.Forms.Padding(4);
this.btnReset.Name = "btnReset";
this.btnReset.Size = new System.Drawing.Size(98, 42);
this.btnReset.TabIndex = 2;
this.btnReset.UseVisualStyleBackColor = true;
this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(11, 34);
this.btnStart.Margin = new System.Windows.Forms.Padding(4);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(98, 42);
this.btnStart.TabIndex = 0;
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.Color.Black;
this.panel1.Location = new System.Drawing.Point(10, 10);
this.panel1.Margin = new System.Windows.Forms.Padding(4);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(642, 464);
this.panel1.TabIndex = 2;
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(225, 34);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(98, 42);
this.btnClose.TabIndex = 7;
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// CameraVideoPlay
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(665, 614);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CameraVideoPlay";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CameraVideoPlay_FormClosing);
this.Load += new System.EventHandler(this.CameraVideoPlay_Load);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.ResumeLayout(false);
}
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.TextBox tbVideoTime;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Button btnReset;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnClose;
#endregion
}
}