C#/C# 연습

WinForm : Video

HicKee 2022. 12. 29. 23:51
using DirectShowLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Test_Media {

    public partial class Form1 : Form {

        string filePath = "경로";

        IGraphBuilder pGrahpBuilder = null;
        IMediaControl pMediaControl = null;

        IMediaEvent pMediaEvent = null;
        EventCode eventCode;

        IVideoWindow pVideoWindow= null;

        public Form1() {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) {


            if (button1.Text == "일시정지") {
                pMediaControl.Pause();

                button1.Text = "재생";
            }
            else { 

                Test();
                button1.Text = "일시정지";
            }
         }

        private void Test() {
            this.Text = filePath;
            pGrahpBuilder = (IGraphBuilder)new FilterGraph();

            pMediaControl = (IMediaControl)pGrahpBuilder;

            pMediaEvent = (IMediaEvent)pGrahpBuilder;

            pVideoWindow = (IVideoWindow)pGrahpBuilder;

            pMediaControl.RenderFile(filePath);

            //재생
            pVideoWindow.put_Owner(panel1.Handle);
            pVideoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings);
            Rectangle rect = panel1.ClientRectangle;
            pVideoWindow.SetWindowPosition(0,0, rect.Right, rect.Bottom);
            pMediaControl.Run();
            Console.WriteLine(pMediaControl.Run());
            

            
        }

        private void button2_Click(object sender, EventArgs e) {

            Console.WriteLine(pMediaControl.Run());

            Marshal.ReleaseComObject(pGrahpBuilder);
            pGrahpBuilder = null;
            Marshal.ReleaseComObject(pMediaControl);
            pMediaControl = null;
            Marshal.ReleaseComObject(pMediaEvent);
            pMediaEvent = null;
            Marshal.ReleaseComObject(pVideoWindow);
            pVideoWindow = null;
        }
    }
}

'C# > C# 연습' 카테고리의 다른 글

WinForm : 로그인  (0) 2022.12.25
WinForm : 퀴즈 게임  (0) 2022.12.24
WinForm : 단순 계산기  (0) 2022.12.21
Class : Student manage  (0) 2022.12.20
Class : Student Score  (0) 2022.12.18