音乐播放器问题

时间:2020-03-18 18:16:31

标签: c# mp3 autoplay axwindowsmediaplayer

我想制作一个既可以播放本地文件又可以播放流的音乐播放器。 为了实现这一点,我正在使用axWindowsMediaPlayer。因此,我一直在努力的问题是如何自动播放库中的下一首歌曲。 首先,我制作了一个库,一个本地SQL数据库,用于存储标题,流派,年份,表演者和歌曲的路径。 我正在提取数据并将其显示在dataGridView中。我设法开始导入歌曲,播放,音量,播放/暂停和进度条。但是现在我找不到如何进行自动播放的功能。 我尝试了几件事,例如制作一个计时器,检查playState是否为MediaEnded。然后,程序应播放ID + 1的歌曲。而且根本不起作用。 我接下来尝试做的是制作一个播放列表,然后在axWindowsMediaPlayer设置中设置autoPlay。但这也不起作用。 您对此有何看法? 这是我尝试过的一些代码:

private void timer2_Tick(object sender, EventArgs e)
    {
        int currentMedia = bunifuCustomDataGrid1.CurrentRow.Index;
        if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
        {
            string s = bunifuCustomDataGrid1.Rows[currentMedia + 1].Cells[3].Value.ToString();
            axWindowsMediaPlayer2.URL = s;
            axWindowsMediaPlayer2.Ctlcontrols.play();
            TagLib.File file = TagLib.File.Create(s);
            string title = file.Tag.Title;
            string author = file.Tag.FirstPerformer;
            string album = file.Tag.Album;
            string year = file.Tag.Year.ToString();
            string genre = file.Tag.FirstGenre;
            TagLib.IPicture p = file.Tag.Pictures[0];
            MemoryStream ms = new MemoryStream(p.Data.Data);
            ms.Seek(0, SeekOrigin.Begin);
            Bitmap bitmap = new Bitmap(ms);
            picCover.BackgroundImage = bitmap;
            lblTItle.Text = author + " - " + title;
            lblAlbumYear.Text = "Album and year: " + album + "/" + year;
            lblGenre.Text = "Genre: " + genre;
        }
        else if(axWindowsMediaPlayer2.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
        {
            string s = bunifuCustomDataGrid1.Rows[currentMedia + 1].Cells[3].Value.ToString();
            axWindowsMediaPlayer1.URL = s;
            axWindowsMediaPlayer1.Ctlcontrols.play();
            TagLib.File file = TagLib.File.Create(s);
            string title = file.Tag.Title;
            string author = file.Tag.FirstPerformer;
            string album = file.Tag.Album;
            string year = file.Tag.Year.ToString();
            string genre = file.Tag.FirstGenre;
            TagLib.IPicture p = file.Tag.Pictures[0];
            MemoryStream ms = new MemoryStream(p.Data.Data);
            ms.Seek(0, SeekOrigin.Begin);
            Bitmap bitmap = new Bitmap(ms);
            picCover.BackgroundImage = bitmap;
            lblTItle.Text = author + " - " + title;
            lblAlbumYear.Text = "Album and year: " + album + "/" + year;
            lblGenre.Text = "Genre: " + genre;
        }
    }

0 个答案:

没有答案