C#winfrom播放音乐

来源:互联网 发布:qt 64位 windows下载 编辑:程序博客网 时间:2024/06/05 02:11

 

使用起来非常简单,下面稍作说明:

1. 支持同步、异步播放

2. 支持循环播放

3. 支持文件和流播放


 

同步播放:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();player.SoundLocation = @"d:/music/happy.mp3";player.Load();player.Play();

异步播放:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();player.SoundLocation = @"d:/music/happy.mp3";player.LoadAsync();player.PlaySync();

循环播放:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();player.SoundLocation = @"d:/music/happy.mp3";player.Load();player.PlayLooping();

 

 private void RePlayer()
        {
            try
            {
                player = new System.Media.SoundPlayer();
                player.SoundLocation = Application.StartupPath + @"/" + appUrl;
                player.PlayLooping();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
           
        }