How to play mp3 files in C#?

前端 未结 7 997
孤独总比滥情好
孤独总比滥情好 2020-12-09 05:13

I\'m trying to play an MP3 file in C# using this guide: http://www.crowsprogramming.com/archives/58

And I\'m doing everything listed, but I still can\'t play any mus

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 05:41

    I'm not sure it's still relevant but when I tried it, it only worked when the code ran not in the main thread, i.e., this.InvokeRequired == false

    So, I would advice you try something like:

    ThreadPool.QueueUserWorkItem(
                 delegate(object param)
                 {
                     WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
                     player.URL = "song.mp3";                     
                 });
    

    player.controls.play() is not needed since the player is set to auto play.

    I'm not sure as to why the main thread won't play correctly but I hope this will help.

提交回复
热议问题