網頁

2011年6月24日 星期五

C# 撥放mp3

solution Explorer上
在References按右鍵
選Add References
選Com加入Windows Media Player (wmp.dll)

 



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 WMPLib; //for mp3

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private WMPLib.WindowsMediaPlayer wmp;  

        private void Form1_Load(object sender, EventArgs e)
        {
            setSound();
   
        }
        //Alert Sounds 
        public void setSound()
        {
            //create object
            wmp = new WMPLib.WindowsMediaPlayer();

            //play music

            //wmp.URL = @"D:\bee.mp3";
            wmp.URL = "bee.mp3";
            wmp.controls.play(); 
        }
    }
}

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。