MP3播放範例
本例是一個播放mp3的範例,播放mp3的方法是使用寫好的類別clsMCI.cs
程式碼前往觀看clsMCI.cs程式碼
程式碼太長這邊貼不下
Form1_KeyPress事件程式碼,意思是按esc關閉程式,按數字鍵1 觸發button1_click事件,按數字鍵2 觸發button2_click事件
Form1程式碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ex23
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
clsMCI cm = new clsMCI();
cm.FileName = "a.mp3";
cm.play();
}
private void button2_Click(object sender, EventArgs e)
{
clsMCI cm = new clsMCI();
cm.FileName = "b.mp3";
cm.play();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Escape)
{
Application.Exit();
}
else
{
if (e.KeyChar == 49)//數字鍵1
{
button1_Click(this, null);
}
else if (e.KeyChar == 50)//數字鍵2
{
button2_Click(this, null);
}
}
}
}
}