123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Windows.Forms;
- using VideoPlayLib;
- namespace Demo
- {
- public partial class MainForm: Form
- {
- private VideoPlay _vp;
- private Form _big;
- public MainForm()
- {
- InitializeComponent();
- }
- #region 自定义消息
- protected override void WndProc(ref Message m)
- {
- MsgPostProc(m);
- base.WndProc(ref m);
- }
- private const int WM_USER = 0x0400;
- private const int MSG_PLAY = WM_USER + 101;
- [DllImport("User32.dll")]
- private static extern int PostMessage(
- IntPtr hWnd, // handle to destination window
- uint msg, // message
- uint wParam, // first message parameter
- uint lParam // second message parameter
- );
- private string MsgPostUrl;
- private void MsgPostPlay(string url)
- {
- MsgPostUrl = url;
- new Thread(
- () => Invoke(
- new Action(
- () =>
- PostMessage(Handle, MSG_PLAY, 0, 0)
- )
- )
- ).Start();
- }
- private void MsgPostProc(Message p)
- {
- if (p.Msg != MSG_PLAY)
- return;
- LoadMediaFile();
- MsgPostUrl = null;
- }
- #endregion 自定义消息
- private void MainForm_Shown(object sender, EventArgs e)
- {
- _big = new Form();
- _big.Show();
- _big.Location = Screen.AllScreens[0].Bounds.Location;
- _big.WindowState = FormWindowState.Maximized;
- _big.FormBorderStyle = FormBorderStyle.None;
- }
- private void btnLoad_DragEnter(object sender, DragEventArgs e)
- {
- e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop)
- ? DragDropEffects.Link
- : DragDropEffects.None;
- }
- private void btnLoad_DragDrop(object sender, DragEventArgs e)
- {
- var filename = ((string[])e.Data.GetData(DataFormats.FileDrop)).First();
- MsgPostPlay(filename);
- }
- private void LoadMediaFile()
- {
- tmrProgress.Stop();
- if (_vp != null)
- _vp.Dispose();
- _vp = new VideoPlay(MsgPostUrl, pnlVideo, _big);
- cboAudioTracks.DataSource = _vp.Audios;
- trkProgress.Minimum = 0;
- trkProgress.Maximum = (int)(_vp.Duration * 10);
- trkProgress.Value = 0;
- }
- private void btnPlay_Click(object sender, EventArgs e)
- {
- _vp.Play();
- tmrProgress.Start();
- }
- private void btnPause_Click(object sender, EventArgs e)
- {
- _vp.Pause();
- tmrProgress.Stop();
- }
- private void cboAudioTracks_SelectedIndexChanged(object sender, EventArgs e)
- {
- _vp.SetAudio(cboAudioTracks.SelectedIndex);
- }
- private void tmrProgress_Tick(object sender, EventArgs e)
- {
- trkProgress.Value = (int)(_vp.CurrentPosition * 10);
- }
- }
- }
|