C# Windows Media Player Audio/Video Play #1
C# 2021. 11. 21. 16:10 |
2021.11.21 - [C#] - C# Windows Media Player Audio/Video Play #2
C#에서 Windows Media Player를 이용해 오디오/비디오 파일을 플레이 해 보자.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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;
using WMPLib;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
axWindowsMediaPlayer1.URL = dlg.FileName;
axWindowsMediaPlayer1.Ctlcontrols.stop(); // 자동 재생 방지.
// The managed-code wrapper for the Windows Media Player control exposes
// the Controls object as Ctlcontrols to avoid collision with the Controls
// property inherited from System.Windows.Forms.Control.
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
}
}
|
소스를 입력한다.
다시 빌드하면 아무 메세지도 나오지 않는다.
이번엔 실행하면 아무것도 보이지 않다가 오디오/비디오 파일을 선택하면 UI없이 플레이 하는 프로그램을 만들어 보자.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
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;
using WMPLib;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
axWindowsMediaPlayer1.Visible = false;
axWindowsMediaPlayer1.uiMode = "none";
}
private void button1_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
axWindowsMediaPlayer1.URL = dlg.FileName;
axWindowsMediaPlayer1.Visible = true;
}
} catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (axWindowsMediaPlayer1.playState == WMPPlayState.wmppsPlaying)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
// The managed-code wrapper for the Windows Media Player control exposes
// the Controls object as Ctlcontrols to avoid collision with the Controls
// property inherited from System.Windows.Forms.Control.
axWindowsMediaPlayer1.Visible = false;
}
}
}
}
|
소스를 입력하고 빌드한다.
실행 파일과 함께 Interop.WMPLib.dll 파일이 존재해야 한다.
Using the Windows Media Player Control in a .NET Framework Solution
'C#' 카테고리의 다른 글
C# Form Designer Layout Mode - 폼 디자이너 레이아웃 모드 (0) | 2021.11.22 |
---|---|
C# Windows Media Player Audio/Video Play #2 (0) | 2021.11.21 |
C# Media Player Mp3 (0) | 2021.11.21 |
C# I Love You Program - 사랑해 프로그램 (0) | 2021.11.20 |
C# - 바탕화면(Desktop)에 출력하기 (0) | 2021.11.20 |