📄 mp3.cs
字号:
lab_no_sound.Visible = false;
btn_add_dir.Visible = false;
btn_add_one.Visible = false;
btn_move_one.Visible = false;
button4.Visible = false;
btn_help.Visible = false;
lab_ctl.BackColor = Color.DarkSlateBlue;
pictureBox2.Location = new Point(-3, 63);
label2.Location = new Point(pictureBox2.Location.X + 18, pictureBox2.Location.Y + 9);
label3.Location = new Point(pictureBox2.Location.X + 124, pictureBox2.Location.Y + 9);
listBox2.Location = new Point(pictureBox2.Location.X + 18, pictureBox2.Location.Y + 34);
}
else
if (bool_ctl_open == true && bool_ctl_open_gecipanel == false)
{
bool_ctl_open = false;
btn_select_play.Visible = false;
listBox1.Visible = false;
lab_no_sound.Visible = false;
btn_add_dir.Visible = false;
btn_add_one.Visible = false;
btn_move_one.Visible = false;
button4.Visible = false;
btn_help.Visible = false;
lab_ctl.BackColor = Color.DarkSlateBlue;
}
}
private void lab_hide_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btn_add_dir_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
string path_dir = fbd.SelectedPath;
File.WriteAllText("LoadMusic.txt",path_dir);
foreach (string filename in Directory.GetFiles(path_dir))
{
FileInfo fi = new FileInfo(filename);
if (fi.Extension == ".mp3" || fi.Extension == ".wma" || fi.Extension == ".MP3" || fi.Extension == ".WMA"||fi.Extension==".Mp3"||fi.Extension==".Wma"||fi.Extension==".wMa"||fi.Extension==".mP3")
{
int i;
for (i = 0; i < listBox1.Items.Count; i++)
{
if (fi.Name == listBox1.Items[i].ToString())
break;
}
if (i == listBox1.Items.Count)
{
listBox1.Items.Add(fi.Name);
axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count, axWindowsMediaPlayer1.newMedia(filename));
}
}
}
}
}
private void btn_add_one_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "mp3,wma Files |*.mp3;*.wma;*.MP3;*.WMA";
ofd.FilterIndex = 1;
if (ofd.ShowDialog() == DialogResult.OK)
{
FileInfo fi = new FileInfo(ofd.FileName);
int i;
for ( i = 0; i < listBox1.Items.Count; i++)
{
if (fi.Name == listBox1.Items[i].ToString())
break;
}
if(i==listBox1.Items.Count)
{
listBox1.Items.Add(fi.Name);
axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count, axWindowsMediaPlayer1.newMedia(ofd.FileName));
}
}
}
private void btn_move_one_Click(object sender, EventArgs e)
{
if(listBox1.Items.Count==1)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
lab_mp3_name.Text = "MusciBaby播放器";
lab_play.Text = "Play";
bool_is_playing = false;
num_music_time = 0;
timer2.Enabled = false;
timer3.Enabled = false;
lab_mp3_name.Text = "MusicBaby";
listBox1.Items.Clear();
axWindowsMediaPlayer1.currentPlaylist.clear();
progressBar1.Value = 0;
lab_xx_xx.Text = "00:00";
lab_now_position.Text = "00:00";
listBox2.Items.Clear();
for (int k = 0; k < str_geci.Length; k++)
str_geci[k] = "";
}
else
if (listBox1.Items.Count > 1)
{
try
{
int j = listBox1.SelectedIndex;
FileInfo fi=new FileInfo(axWindowsMediaPlayer1.currentMedia.sourceURL);
if (fi.Name==listBox1.SelectedItem.ToString())
MessageBox.Show("当前歌曲正在播放,不可移除!", "警告!");
else
{
axWindowsMediaPlayer1.currentPlaylist.removeItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(j));
listBox1.Items.RemoveAt(j);
}
}
catch
{
}
}
}
private void button4_Click(object sender, EventArgs e)
{
if (listBox1.Items.Count > 0)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
lab_mp3_name.Text = "MusciBaby播放器";
lab_play.Text = "Play";
bool_is_playing = false;
num_music_time = 0;
timer2.Enabled = false;
timer3.Enabled = false;
lab_mp3_name.Text = "MusicBaby";
listBox1.Items.Clear();
axWindowsMediaPlayer1.currentPlaylist.clear();
progressBar1.Value = 0;
lab_xx_xx.Text = "00:00";
lab_now_position.Text = "00:00";
listBox2.Items.Clear();
for (int k = 0; k < str_geci.Length; k++)
str_geci[k] = "";
}
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
axWindowsMediaPlayer1.settings.volume = trackBar1.Value;
}
private void timer2_Tick(object sender, EventArgs e)
{
if (sender == timer2)
{
getGeci_str();
getList2_add_geci();
progressBar1.Maximum = (int)axWindowsMediaPlayer1.currentMedia.duration;
progressBar1.Minimum = 0;
progressBar1.Step = (int)(progressBar1.Maximum / 20);
progressBar1.Value = (int)axWindowsMediaPlayer1.Ctlcontrols.currentPosition;
lab_xx_xx.Text = axWindowsMediaPlayer1.currentMedia.durationString;
lab_now_position.Text = axWindowsMediaPlayer1.Ctlcontrols.currentPositionString;
if (num_music_time >= axWindowsMediaPlayer1.currentMedia.duration - 4)
{
listBox2.Items.Clear();
for (int k = 0; k < str_geci.Length; k++)
str_geci[k] = "";
if (bool_cyle == false || listBox1.Items.Count == 1)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
axWindowsMediaPlayer1.Ctlcontrols.play();
is_playing();
}
if (bool_cyle == true && listBox1.Items.Count > 1)
{
axWindowsMediaPlayer1.Ctlcontrols.next();
lab_mp3_name.Text = axWindowsMediaPlayer1.currentMedia.name;
is_playing();
}
num_music_time = 0;
}
else
num_music_time++;
}
}
private void btn_select_play_Click(object sender, EventArgs e)
{
if (listBox1.Items.Count > 0)
{
int j = listBox1.SelectedIndex;
try
{
axWindowsMediaPlayer1.Ctlcontrols.playItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(j));
lab_mp3_name.Text = axWindowsMediaPlayer1.currentMedia.name;
lab_play.Text = "Pause";
bool_is_playing = true;
num_music_time = 0;
timer2.Enabled = true;
timer3.Enabled = true;
progressBar1.Value = (int)axWindowsMediaPlayer1.Ctlcontrols.currentPosition;
lab_xx_xx.Text = axWindowsMediaPlayer1.currentMedia.durationString;
bool_ever_played_music = true;
listBox2.Items.Clear();
for (int k = 0; k < str_geci.Length; k++)
str_geci[k] = "";
}
catch
{
}
}
}
private void is_playing()
{
int j;
for (j = 0; j < listBox1.Items.Count; j++)
{
if (axWindowsMediaPlayer1.currentMedia.sourceURL == axWindowsMediaPlayer1.currentPlaylist.get_Item(j).sourceURL)
break;
}
listBox1.SetSelected(j,true);
}
private void label1_Click(object sender, EventArgs e)
{
if (bool_no_sound == false)
{
num_sound_value = trackBar1.Value;
bool_no_sound = true;
label1.Text = "Sound";
trackBar1.Value = 0;
axWindowsMediaPlayer1.settings.volume = 0;
}
else
{
bool_no_sound = false;
trackBar1.Value = num_sound_value;
axWindowsMediaPlayer1.settings.volume = num_sound_value;
label1.Text = "静音";
}
}
private void Loadmusics()
{
try
{
foreach (string filename in Directory.GetFiles(str_load_dir))
{
FileInfo fi = new FileInfo(filename);
if (fi.Extension == ".mp3" || fi.Extension == ".wma" || fi.Extension == ".MP3" || fi.Extension == ".WMA")
{
listBox1.Items.Add(fi.Name);
axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count, axWindowsMediaPlayer1.newMedia(filename));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -