如何使用 axmediaplayer 播放播放列表中的下一个项目?
好的,我有问题,我编写了此代码来根据列表框中列出的项目播放 axmediaplayer。 首先,我编写此代码以使用 opendialog 制作列表:
private string[] files, path;
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
files = openFileDialog1.SafeFileNames;
path = openFileDialog1.FileNames;
for (int i = 0; i < files.Length; i++) {
listBox1.Items.Add(files[i]);
}
}
}
然后当列表框索引更改时(当列表框中的项目单击时)使用此代码播放音乐:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = path[listBox1.SelectedIndex];
}
它工作正常,然后我希望播放器自动移动到下一首歌曲基于我的列表框中的项目。使用事件 PlayStateChange,所以我将此代码
private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
if(listBox1.SelectedIndex < files.Length - 1)
{
listBox1.SelectedIndex = listBox1.SelectedIndex + 1;
}
}
}
更改为选定的索引,但播放器不会自动播放下一首歌曲。我必须手动单击播放按钮才能播放列表。有人可以帮我吗?
ok i have question, i made this code to play axmediaplayer base on item listed on listbox.
first i make this code to make a list using opendialog :
private string[] files, path;
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
files = openFileDialog1.SafeFileNames;
path = openFileDialog1.FileNames;
for (int i = 0; i < files.Length; i++) {
listBox1.Items.Add(files[i]);
}
}
}
and then it play the music when the listbox index changed (when the item on the list box cliked) using this code :
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = path[listBox1.SelectedIndex];
}
it works fine, and then i want player to automove to the next song base on item on my listbox. with using events PlayStateChange, so i make this code
private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
if(listBox1.SelectedIndex < files.Length - 1)
{
listBox1.SelectedIndex = listBox1.SelectedIndex + 1;
}
}
}
the selected index change, but the player doesn't auto play the next song. i must click the play button manually in order to play the list. can anyone help me up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我找到了,解决方案是在播放下一首歌曲之前添加计时器。
首先我添加计时器,应该是timer1。然后我将 playstate 事件更改为如下所示:
然后在计时器上添加刻度事件,刻度事件是这样的:
现在它工作正常 ^^
ok i found it, the solution is to add timer before playing the next song.
first im adding timer, that shoud be timer1. and then i change playstate event to something like this :
then on the timer i adding tick event, the tick event is something like this :
now its work fine ^^
以下功能对我有用:
Below functionality worked for me: