加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

mciSendString如何实现循环播放

(2012-11-15 10:45:45)
标签:

mcisendstring

循环播放

it

分类: C#开发

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);//播放
        }

    }
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有