播放音乐(mciSendString)

1.需要引用命名空间using System.Runtime.InteropServices;

这里只是做了个简单的播放功能,想了解更多查看它的官方文档

       [DllImport("winmm.dll")]
        private static extern uint mciSendString(string lpstrCommand,
                                string lpstrReturnString, uint uReturnLenth, uint hWndCallback);
        /// 
        /// 播放指定的音乐
        /// 
        /// 
        public static void Play(string sound_Path)
        {
            mciSendString(@"colse temp_alias", null, 0, 0);
            mciSendString("open \""+sound_Path +"\" alias temp_alias", null, 0, 0);//注意open后有一个空格,alias前面有一个空格
            mciSendString("play temp_alias repeat", null, 0, 0);
        }
        /// 
        /// 暂停播放
        /// 
        public static void Pause()
        {
            mciSendString(@"stop temp_alias", null, 0, 0);
        }
        /// 
        /// 播放停止
        /// 
        public static void Stop()
        {
            mciSendString(@"close temp_alias",null,0,0);
        }

 

你可能感兴趣的:(播放音乐(mciSendString))