读书人

C#播放器有关问题 新手有关问题

发布时间: 2013-08-04 18:26:15 作者: rapoo

C#播放器问题 新手问题
string str = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "播放列表文件|*.mp4";
ofd.Title = "打开视频播放列表";
if (ofd.ShowDialog() == DialogResult.OK)
{
str = ofd.FileName;

}
if (播放函数)
{

return;

}
else if (停止函数)
{

}
else
{
return;
}
}
请问一下我这个循环 哪个大神可以帮我改一下,如果代码不全的话跟我说一声我加代码。 C# 视频
[解决办法]
有循环么?...
[解决办法]
我有个播放器代码 供你参考 你那个写的什么 我就没看懂

 public partial class Form1 : Form
{
public Form1()
{


InitializeComponent();
}
string[] fileList = new string[10000]; // 定义播放列表数的最大值
int numOfMusic; //选中的媒体文件的索引号
int selectOne;//选中的音乐文件
bool playOne = false; // 控制是否循环播放
public void AddFile(string path)
{
if (numOfMusic < 10000)
{
numOfMusic += 1;
fileList[numOfMusic] = path;
}
else
{
MessageBox.Show("不能添加文件!", "播放列表已满");
}
}
private void Form1_Load(object sender, EventArgs e)
{
lstFileList.Items.CopyTo(fileList, 0); //将列表框(lstFileList)中的列表项全部复制到数组(fileList)中
numOfMusic = 0; // 选中第一个媒体文件
CloseBtn();
}
//添加歌曲
public void AddFiles(string path, ListBox lstFiles)
{

DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileInfo f in dir.GetFiles("*.mp3"))
{
AddFile(f.FullName);


int i;
string strFile = Convert.ToString(numOfMusic);
for (i = 1; i <= 5 - strFile.Length; i++)
{
strFile += "";
}
strFile = f.Name;
lstFileList.Items.Add(strFile);
}
foreach (DirectoryInfo d in dir.GetDirectories())
{
AddFiles(d.FullName, lstFileList);
}
}


//删除歌曲
public void DelFile(int selectNum)
{
int i;
for (i = selectNum; i <= numOfMusic - 1; i++)
{
fileList[i] = fileList[i + 1];

}
numOfMusic -= 1;
}

public void CloseBtn()
{
btnPlay.Enabled = false;
btnBack.Enabled = false;
btnForward.Enabled = false;


btnStop.Enabled = false;
btnReplay.Enabled = false;
btnDelete.Enabled = false;

}



public void Play(int selectNum)
{
mediaPlayer.URL = fileList[selectNum]; //播放选中的媒体文件
this.Text = "正在播放-- " + lstFileList.SelectedItem.ToString();
}
public void OpenBtn()
{
btnPlay.Enabled = true;
btnBack.Enabled = true;
btnForward.Enabled = true;
}
private void button8_Click(object sender, EventArgs e)
{
mediaPlayer.URL = "";
this.Text = "媒体播放器";
tmrMedia.Enabled = false;
btnReplay.Enabled = false;
lstFileList.SelectedIndex = selectOne - 1;
}

private void lstFileList_Click(object sender, EventArgs e)
{
int i;
odlgMedia.FileName = "";
// 设置默认文件名
odlgMedia.InitialDirectory = "C:\\";
// 设置默认路径
odlgMedia.Filter = "mp3文件


[解决办法]
*.mp3
[解决办法]
所有文件
[解决办法]
*.*";
//设置文件类型
if (odlgMedia.ShowDialog() == DialogResult.OK)
{
string path = odlgMedia.FileName;
FileInfo f = new FileInfo(path);
AddFile(f.FullName);
string strFile = Convert.ToString(numOfMusic);
for (i = 1; i <= 5 - strFile.Length; i++)
{
strFile += "";

}
strFile = f.Name;
lstFileList.Items.Add(strFile);
if (lstFileList.Items.Count > 0)
{
OpenBtn();
}
}
}

private void button1_Click(object sender, EventArgs e)
{
fbdlaMedia.SelectedPath = "c:\\";

fbdlaMedia.ShowNewFolderButton = true;



fbdlaMedia.Description = "请选择媒体文件目录:";

fbdlaMedia.ShowNewFolderButton = false;

if (fbdlaMedia.ShowDialog() == DialogResult.OK)
{

AddFiles(fbdlaMedia.SelectedPath, lstFileList);

if (lstFileList.Items.Count > 0)
{

OpenBtn();
}
}
}

private void btnDelete_Click(object sender, EventArgs e)
{
int i = lstFileList.SelectedIndex;
if (lstFileList.SelectedIndex >= 0)
{
if ((selectOne == lstFileList.SelectedIndex + 1) && (mediaPlayer.URL != ""))
{
MessageBox.Show("不能删除正在播放的文件", "错误");
}
else
{
DelFile(i + 1);
lstFileList.Items.RemoveAt(i);
if (i < lstFileList.Items.Count)


{
lstFileList.SelectedIndex = i;
}
else if (lstFileList.Items.Count == 0)
{
CloseBtn();
}
else
{
lstFileList.SelectedIndex = 0;
}
}
}
}
private void btnPlay_Click(object sender, EventArgs e)
{
if (lstFileList.SelectedIndex < 0)
{
selectOne = 1;
lstFileList.SelectedIndex = 0;

}
else
{
selectOne = lstFileList.SelectedIndex + 1;
}
Play(selectOne);


tmrMedia.Enabled = true;
btnStop.Enabled = true;
btnReplay.Enabled = true;
}
private void lstFileList_SelectedIndexChanged(object sender, EventArgs e)
{
btnDelete.Enabled = true;
}
private void btnBack_Click(object sender, EventArgs e)
{
if (lstFileList.SelectedIndex > 0)
{
lstFileList.SelectedIndex -= 1;

}
else if (lstFileList.SelectedIndex == 0)
{

lstFileList.SelectedIndex = lstFileList.Items.Count - 1;
}
else
{
lstFileList.SelectedIndex = numOfMusic - 1;
}
selectOne = lstFileList.SelectedIndex + 1;
Play(selectOne);
btnStop.Enabled = true;
btnReplay.Enabled = true;

}
private void button6_Click(object sender, EventArgs e)
{
if (lstFileList.SelectedIndex < lstFileList.Items.Count - 1)


{
lstFileList.SelectedIndex = lstFileList.SelectedIndex + 1;
}
else
{
if (lstFileList.SelectedIndex > 0)
{
lstFileList.SelectedIndex = 0;
}
}
selectOne = lstFileList.SelectedIndex + 1;
Play(selectOne);
btnStop.Enabled = true;
btnReplay.Enabled = true;
}
private void btnReplay_Click(object sender, EventArgs e)
{
if (playOne == true)
{
playOne = false;

btnReplay.FlatStyle = FlatStyle.Standard;
// 设置按钮外观为三维

btnReplay.Text = "单曲循环";
}
else
{
playOne = true;
btnReplay.FlatStyle = FlatStyle.Popup;


// 设置按钮外观为平面显示

btnReplay.Text = "取消循环";

}
lstFileList.SelectedIndex = selectOne - 1;

}
private void lstFileList_DoubleClick(object sender, EventArgs e)
{
//双击播放列表中的媒体文件时,则播放该文件
btnPlay_Click(sender, e);
playOne = false;
btnReplay.Text = "单曲循环";
}
}

读书人网 >C#

热点推荐