C# Lecteur MP3 à l'aide winmm.dll

Je suis en train de bash ensemble une (très) approximative lecteur MP3 pendant mon heure de dîner, et jusqu'à présent j'ai réussi à lire les fichiers, et je suis en train de travailler sur une façon de construire une liste de noms de fichiers pour permettre aléatoire des chansons, mais je pense que j'ai juste frappé un hic.

Est-il un moyen de savoir quand le cours de lecture MP3 a fini? Un événement ou quelque chose du genre? Tel qu'il est, je ne pense pas que je serais capable d'avoir des listes de lecture etc, sauf si cela a été possible grâce à elle, s'arrêtant après chaque lecture.

J'ai attatched l'ensemble de la source ci-dessous, n'hésitez pas à chercher en dehors et de me donner vos commentaires, merci.

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace X
{
public partial class Form1 : Form
{
List<string> Names = new List<string>();
StreamReader reader = File.OpenText(@"C:\X.txt");
string line;
OpenFileDialog ofd = new OpenFileDialog();
StringBuilder buffer = new StringBuilder(128);
string CommandString;
[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);
public Form1()
{
InitializeComponent();
while ((line = reader.ReadLine()) != null)
{
if (line.Trim() != "")
{
Names.Add(line.Trim());
}
}
}
private void btnplay_Click(object sender, EventArgs e)
{
if (ofd.FileName == "")
{
if (ofd.ShowDialog() == DialogResult.OK)
{
ofd.Filter = "MP3 Files|*.mp3";
CommandString = "open " + "\"" + ofd.FileName + "\"" + " type MPEGVideo alias Mp3File";
mciSendString(CommandString, null, 0, 0);
CommandString = "play Mp3File";
mciSendString(CommandString, null, 0, 0);
}
}
else
{
CommandString = "play Mp3File";
mciSendString(CommandString, null, 0, 0);
}
}
private void btnpause_Click(object sender, EventArgs e)
{
CommandString = "pause mp3file";
mciSendString(CommandString, null, 0, 0);
}
private void btnbrowse_Click(object sender, EventArgs e)
{
ofd.Filter = "Mp3 files |*.mp3";
if (ofd.ShowDialog() == DialogResult.OK)
{
txtpath.Text = ofd.FileName;
CommandString = "close Mp3File";
mciSendString(CommandString, null, 0, 0);
CommandString = "open " + "\"" + ofd.FileName + "\"" + " type MPEGVideo alias Mp3File";
mciSendString(CommandString, null, 0, 0);
}
}
}
}
InformationsquelleAutor JoeBeez | 2010-03-02