none
我用API播放一段MP3音频,我想中途停止怎么做呢?求帮助 RRS feed

  • 问题

  •          /// <summary>
             /// 使用API
             /// </summary>
             public static uint SND_ASYNC = 0x0001; //playasynchronously 
            public static uint SND_FILENAME = 0x00020000; // name is file name
            [DllImport("winmm.dll")]
            public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
            [DllImport("Kernel32", CharSet = CharSet.Auto)]
            static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength);
            string tempStr = "";
            private void GoShoot()
            {
                string name = Application.StartupPath + @"\123.mp3";
                StringBuilder shortpath = new StringBuilder(80);
                int result = GetShortPathName(name, shortpath, shortpath.Capacity);
                name = shortpath.ToString();
                mciSendString(@"close all", null, 0, 0);
                mciSendString(@"open " + name + " alias song", null, 0, 0); //打开
                mciSendString("play song", null, 0, 0); //播放
                
            }

    我用上面这段代码,播放一段MP3音效,我想中途停止播放,怎么做?求帮助

    我尝试使用

    mciSendStringf("close song",null,0,0);

    mciSendString("close all",null,0,0);

    但是没反应

    2013年6月19日 7:07

答案

  • mciSendString("pause song", null, 0, 0); //暫停

    mciSendString("resume song", null, 0, 0); //播放


    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    • 已标记为答案 Mclovin 2013年6月20日 3:15
    2013年6月19日 8:53

全部回复