C# WindowsMediaPlayer 的一些用法实例

时间:2022-08-24 21:00:41

播放单首歌曲

 

复制代码代码如下:

player.URL = "歌曲文件路径";
player.Ctlcontrols.play();

 

添加多首歌曲到播放列表

 

复制代码代码如下:


IWMPPlaylist playList = player.playlistCollection.newPlaylist("MyPlayList"); //新建列表
            IWMPMedia media;

 

            foreach (DataRow drItem in MusicSettings.DtMusic.Rows)
            {
                media = player.newMedia(drItem["路径"].ToString()); //参数为歌曲路径
                playList.appendItem(media);
            }

            player.currentPlaylist = playList;
            player.Ctlcontrols.play();    //开始播放

 

 或者直接在当前列表上添加

 

复制代码代码如下:


player.currentPlaylist.clear();

 

            IWMPMedia media;

            foreach (DataRow drItem in MusicSettings.DtMusic.Rows)
            {
                media = player.newMedia(drItem["路径"].ToString()); //参数为歌曲路径
                player.currentPlaylist.appendItem(media);
            }


设置播放器音量

 

 

复制代码代码如下:

 player.settings.volume=100;