Advertisement
Fhernd

Principal.cs

Mar 16th, 2018
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using QuartzTypeLib;
  4.  
  5. namespace R812ReproducirVideo
  6. {
  7.     public partial class Principal : Form
  8.     {
  9.         // Constante del estilo de ventana:
  10.         private const int WS_CHILD = 0x40000000;
  11.         private const int WS_CHIPCHILDREN = 0x000000;
  12.  
  13.         // Referencia a la interfaz de control multimedia>
  14.         private IMediaControl mc = null;
  15.  
  16.         // Referncia a la ventana de vídeo sobre el formulario:
  17.         private IVideoWindow ventanaVideo = null;
  18.  
  19.         public Principal()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void btnReproducirVideo_Click(object sender, EventArgs e)
  25.         {
  26.             OpenFileDialog ofd = new OpenFileDialog();
  27.             ofd.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp3;*.mp4|All Files|*.*";
  28.  
  29.             if (DialogResult.OK == ofd.ShowDialog())
  30.             {
  31.                 if (mc != null)
  32.                 {
  33.                     mc.Stop();
  34.                 }
  35.  
  36.                 FilgraphManager grapManager = new FilgraphManager();
  37.                 grapManager.RenderFile(ofd.FileName);
  38.  
  39.                 try
  40.                 {
  41.                     ventanaVideo = (IVideoWindow) grapManager;
  42.                     ventanaVideo.Owner = (int) pbxVideo.Handle;
  43.                     ventanaVideo.WindowStyle = WS_CHILD | WS_CHIPCHILDREN;
  44.  
  45.                     ventanaVideo.SetWindowPosition(
  46.                         pbxVideo.ClientRectangle.Left,
  47.                         pbxVideo.ClientRectangle.Top,
  48.                         pbxVideo.ClientRectangle.Width,
  49.                         pbxVideo.ClientRectangle.Height
  50.                     );
  51.                 }
  52.                 catch
  53.                 {
  54.                     // Gestión eventual de errores.
  55.                 }
  56.  
  57.                 mc = (IMediaControl) grapManager;
  58.                 mc.Run();
  59.             }
  60.         }
  61.  
  62.         private void pbxVideo_SizeChanged(object sender, EventArgs e)
  63.         {
  64.             if (ventanaVideo != null)
  65.             {
  66.                 try
  67.                 {
  68.                     ventanaVideo.SetWindowPosition(
  69.                         pbxVideo.ClientRectangle.Left,
  70.                         pbxVideo.ClientRectangle.Top,
  71.                         pbxVideo.ClientRectangle.Width,
  72.                         pbxVideo.ClientRectangle.Height
  73.                     );
  74.                 }
  75.                 catch
  76.                 {
  77.                     // Gestión eventual de errores.
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement