C# mciSendString()實現迴圈播放音樂

來源:互聯網
上載者:User

聲明這是 微軟論壇上看的. 我看了很多人都在尋找C#   mciSendString()迴圈播放音樂
學英語重要呀。

using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace PlayMp3WithWindow
{
    public partial class Form1 : Form
    {
        public const int MM_MCINOTIFY = 0x3B9;  //這是聲明 播完音樂 mciSendString()向系統發送的指令

        [DllImport("winmm.dll")]
        private static extern long mciSendString(string command,
                                                    StringBuilder returnString,
                                                    int returnSize,
                                                    IntPtr hwndCallback);
        public Form1()
        {
            InitializeComponent();

            PlaySong(@"123.mp3");  // when complete callback to DefWndProc

                                              //歌曲路徑,開始就播放這個     

        }

        protected override void DefWndProc(ref Message m)
        {
            base.DefWndProc(ref m);            

        if (m.Msg == MM_MCINOTIFY) //判斷指令是不是MM_MCINOTIFY

                          //當歌曲播完 mciSendString()向系統發送的MM_MCINOTIFY指令
            {
                PlaySong(@"456.mp3");//播完就自動播放這個。。。
            }
        }

        public void PlaySong(string file)
        {
            mciSendString("close media", null, 0, IntPtr.Zero);//關閉
            mciSendString("open \"" + file + "\" type mpegvideo alias media", null, 0, IntPtr.Zero);

//開啟  file 這個路徑的歌曲 " ,type mpegvideo是檔案類型  ,    alias 是將檔案別名為media 
            mciSendString("play media notify", null, 0, this.Handle);//播放
        }

    }
}

 seo:http://greatverve.cnblogs.com/archive/2011/06/24/mciSendString.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.