在你的另外一个帖子中推荐了下你使用WPF中的MediaPlayer,不知道你这里是不是一定要使用你自己的Mp3的类,你的代码我经过修改以后,没什么问题,但是还是我原来的方案,使用WPF中的技术
在你的项目中添加PresentationCore和WindowsBase的引用,然后修改你的播放代码如下:        int i = 0;
        private void mp3play()
        {
            //ThreadPool.QueueUserWorkItem((obj) =>
            //{
                string src;
                //foreach (string lrc in mp3lrc)
                //{
                    //Mp3 mp3 = new Mp3();
                    
                    //src = System.IO.Path.GetFullPath(src);
                    //mp3.FileName = src;
                    //mp3.play();
                    //while (!mp3.IsEnd())
                    //{
                    //}
               // }
            //});
                System.Windows.Media.MediaPlayer player = new System.Windows.Media.MediaPlayer();
                src = "../../Ebook/sound/" + mp3lrc[i] + ".mp3";
                player.Open(new Uri(src, UriKind.Relative));
                player.Play();
                player.MediaEnded += new EventHandler(player_MediaEnded);
        }        private void player_MediaEnded(object sender, EventArgs e)
        {
            i++;
            if (i >= mp3lrc.Count) {
                return;
            }
            string src;
            System.Windows.Media.MediaPlayer player = new System.Windows.Media.MediaPlayer();
            src = "../../Ebook/sound/" + mp3lrc[i] + ".mp3";
            player.Open(new Uri(src, UriKind.Relative));
            player.Play();
            player.MediaEnded += new EventHandler(player_MediaEnded);
        }

解决方案 »

  1.   

    ilong = APIClass.mciSendString(Name, TemStr, TemStr.Length, 0); 
    所使用的参数都一样的
    主线程 运行后:ilong=0 CurrentPosition赋值0 Duration赋值3 dueLenth由"\0"→"3214\0"
    而另起线程 运行后:ilong=266 CurrentPosition和Duration没有被赋值 所以异常 dueLenth未发生变动
    原因什么的完全不明白
      

  2.   

    ilong = APIClass.mciSendString(Name, TemStr, TemStr.Length, 0); 
    所使用的参数都一样的
    主线程 运行后:ilong=0 CurrentPosition赋值0 Duration赋值3 dueLenth由"\0"→"3214\0"
    而另起线程 运行后:ilong=266 CurrentPosition和Duration没有被赋值 所以异常 dueLenth未发生变动
    原因什么的完全不明白没有赋值,那是因为没有把参数传进去吧public class CParam

      //Params 
      public int param1{get;set;}
      public string parma2{get;set;}
      
    }
    //启动线程
        //参数赋值
        CParam mParam = new CParam();
       mParam.param1 = 1;
       //启动线程
       Thread Worker = new Thread(new ParameterizedThreadStart(CheckThread));
                Worker.IsBackground = true;
                Worker.Start(mConfig);    private void CheckThread(object param)
        {       //获取传入的参数
                CParam mCon = (CParam )param;
                //DO something
        }
      

  3.   

    http://stackoverflow.com/questions/3597681/method-doesnt-work-when-executed-in-a-thread-but-works-otherwise-c-sharp参考下这里吧:
    I suspect that MCI functions may needs a Message Loop running. Besides, MCI requests are unblocking so your thread will die once you invoke the MCI operation. You need to keep running the message loop on that thread (using Application.Run) till MCI finishes (you will know that by requesting the callback by passing the window handle). See this article that illustrates how it is done.Edit: Perhaps a hidden form launched over new thread can reduce the work do be done. But you still need to receive callback from MCI to terminate the thread.
    我觉得可能是这个原因,因为我在使用BackgroundWorker以及各种多线程方法以后,都无法成功播放声音
      

  4.   


                Thread UIThread = new Thread((ThreadStart)delegate
                {
                    mp3play();
                });
                UIThread.SetApartmentState(ApartmentState.STA);
                UIThread.IsBackground = true;
                UIThread.Start();你懂的