我正在尝试在午餐时间将一个(非常)粗糙的 MP3 播放器组合在一起,到目前为止,我已经可以播放文件,并且我正在研究一种构建文件名列表以启用随机歌曲的方法,但我想我刚刚遇到了障碍。
有没有办法知道当前播放的 MP3 何时结束?活动之类的?就目前而言,我认为我不能拥有播放列表等,除非这是可能的,因为它在每次播放后都会停止。
我已经在下面附上了整个来源,请随时将其分开并给我您可能有的任何反馈,干杯。
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);
}
}
}
}