简单做了个播放器,获得的歌名都是带了路径的,现在想要只显示歌名,点击就能播放这点问题还没解决,试着用字符串截取做的,但是不行,在这里分享给大家,望大神能把我的这点小问题解决解决,感激不敬!谢谢
------------------------------------------播放器-------------------------------------------
using System;
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.IO;
namespace FRM_MediaPlayer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = @"C:\Users\Administrator\Music\music\张悬 - 宝贝.mp3";
string[] files = Directory.GetFiles(@"C:\Users\Administrator\Music\music");
for (int i = 0; i < files.Length; i++)
{
listBox1.Items.Add(files[i]);
}
}
private void 添加音乐文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();//创建文件对话框对象
dialog.Multiselect = true;//文件多项选择属性设置为true
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)//判断对话框是否打开
{
string[] files = dialog.FileNames;//获取已选的文件数组
foreach (string file in files)
{
listBox1.Items.Add(file);//添加到列表
}
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
}
private void 删除选中歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
{
//listBox1.MultiColumn=true;
//listBox1.SelectedItems.ToString();
//listBox1.SelectedItems.Remove();
}
}
}
|
|