Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# axWindowsMediaPlayer崩溃程序_C#_Mp3_Axwindowsmediaplayer - Fatal编程技术网

C# axWindowsMediaPlayer崩溃程序

C# axWindowsMediaPlayer崩溃程序,c#,mp3,axwindowsmediaplayer,C#,Mp3,Axwindowsmediaplayer,我正在尝试制作一个具有播放列表功能的MP3播放器,我在谷歌搜索了所有地方,尝试了一些例子,但都没有效果。当p[ListBox1.SelectedIndex+1]时,代码冻结在被调用,我不知道为什么它会锁定程序。我试着制作一个数组并通过它选择下一首歌,但这也不起作用 我认为这是最简单的方法。但出于某种原因,它锁定了程序 using System; using System.Collections.Generic; using System.ComponentModel; using System.

我正在尝试制作一个具有播放列表功能的MP3播放器,我在谷歌搜索了所有地方,尝试了一些例子,但都没有效果。当
p[ListBox1.SelectedIndex+1]时,代码冻结在被调用,我不知道为什么它会锁定程序。我试着制作一个数组并通过它选择下一首歌,但这也不起作用

我认为这是最简单的方法。但出于某种原因,它锁定了程序

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Threading;
using System.Collections;

namespace MusicPlayer
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    string[] f, p;
    ArrayList playlist = new ArrayList();
    private int current_index = 0;

    private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog open = new OpenFileDialog();

        if(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK){
            f = openFileDialog1.SafeFileNames;
            p = openFileDialog1.FileNames;

            for (int i = 0; i < f.Length; i++)
            {
                listBox1.Items.Add(f[i]);
            }

            foreach (string d in open.FileNames)
            {
                listBox1.Items.Add(d);
            }
        }
    }

    private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        axWindowsMediaPlayer1.URL = p[listBox1.SelectedIndex];
    }


    private void Form1_Load(object sender, EventArgs e)
    {
        axWindowsMediaPlayer1.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(MediaPlayer_PlayStateChange);
    }

    public void MediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        switch (axWindowsMediaPlayer1.playState)
        {
            // Locks up here
            case WMPLib.WMPPlayState.wmppsReady:
                axWindowsMediaPlayer1.URL = p[listBox1.SelectedIndex + 1];
                break;
            case WMPLib.WMPPlayState.wmppsStopped:
                axWindowsMediaPlayer1.URL = p[listBox1.SelectedIndex + 1];
                break;
            default:
                break;
        }
    }
}
}

但是当我运行这个程序时,它会陷入“媒体更改”的困境,最终什么也不做。

PlayStateChange是一个棘手的事件,递归到控件中非常麻烦。将代码延迟为。现在它被困在“媒体更改”中
public void MediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
 switch (axWindowsMediaPlayer1.playState)
 {
   case WMPLib.WMPPlayState.wmppsReady:                                     
    axWindowsMediaPlayer1.BeginInvoke(new Action(change_song));
    break;
    case WMPLib.WMPPlayState.wmppsStopped:
     axWindowsMediaPlayer1.BeginInvoke(new Action(change_song));
     break;
     default:
     break;
}
}

void change_song()
{
  axWindowsMediaPlayer1.URL = p[listBox1.SelectedIndex + 1];
}