一°?
曲¨²"Grid.Column="2"Name="btnnext"Click="btnnext_Click"Foreground="Blue"BorderBrush="Blue"BorderThickness="5">
后台源代码:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Data;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Imaging;
usingSystem.Windows.Navigation;
usingSystem.Windows.Shapes;
usingSystem.Windows.Forms;
usingSystem.IO;
usingSystem.Runtime;
usingSystem.Windows.Media.Animation;
usingSystem.Threading;
namespace音°?
乐¤?
播£¤放¤?
器¡Â
{
///
///MainWindow.xaml的Ì?
交?
互£¤逻?
辑-
///
publicpartialclassMainWindow:
Window
{
Lists=newList();
byte[]bs;
Liststr8=null;
privatebool?
flag=null;
privatebool?
flag1;
FolderBrowserDialogfbd=newFolderBrowserDialog();
StringBuildersb=newStringBuilder();
privatestring[]strm=null;
publicMainWindow()
{
InitializeComponent();
}
privatevoidWindow_Loaded(objectsender,RoutedEventArgse)
{
flag=null;
flag1=null;
str8=newList();
slidvolume.Value=0.3;
me.Volume=0.3;
txttataltime.Content=me.Position.ToString();
txtruntime.Content=me.Position.ToString();
listBox1.Items.Clear();
FileStreamfs1=newFileStream(AppDomain.CurrentDomain.BaseDirectory+"\\歌¨¨曲¨²列¢D表À¨ª.txt",FileMode.OpenOrCreate,FileAccess.Read,FileShare.ReadWrite);
byte[]bt=newbyte[fs1.Length];
fs1.Read(bt,0,bt.Length);
stringstr=Encoding.Default.GetString(bt);
string[]str4=str.Split(newstring[]{"\r\n"},StringSplitOptions.None);
s=str4.Distinct().ToList();
for(inti=0;i<=s.Count-1;i++)
{
if(s[i].LastIndexOf("\\")>=0)
{
listBox1.Items.Add(s[i].Substring(s[i].LastIndexOf("\\")+1));
str8.Add(s[i].Substring(0,s[i].LastIndexOf("\\")));
}
}
System.Windows.Forms.Timert=newSystem.Windows.Forms.Timer();
t.Enabled=true;
t.Tick+=newEventHandler(t_Tick);
t.Interval=1100;
t.Start();
}
privatevoidbtnfor_Click(objectsender,RoutedEventArgse)
{
try
{
if(flag1==null)
{
listBox1.SelectedIndex--;
}
if(flag1==true)
{
Randomrnd=newRandom();
listBox1.SelectedIndex=rnd.Next(0,listBox1.Items.Count-1);
}
if(flag1==false)
{
}
if(listBox1.SelectedIndex<0)
{
(listBox1.SelectedIndex)=(listBox1.Items.Count-1);
}
musicplay();
}
catch{System.Windows.Forms.MessageBox.Show("请?
选?
择?
歌¨¨曲¨²");}
}
privatevoidbtnnext_Click(objectsender,RoutedEventArgse)
{
if(flag1==null)
{
if(listBox1.SelectedIndex{
listBox1.SelectedIndex++;
musicplay();
return;
}
if(listBox1.SelectedIndex>=listBox1.Items.Count-1)
{
(listBox1.SelectedIndex)=0;
}
}
if(flag1==true)
{
Randomrnd=newRandom();
listBox1.SelectedIndex=rnd.Next(0,listBox1.Items.Count-1);
}
if(flag1==false)
{
}
musicplay();
}
privatevoidbtnplayhold_Click(objectsender,RoutedEventArgse)
{
if(flag==true)
{
btnplayhold.Content="暂Y停ª¡ê";
me.Pause();
flag=false;
return;
}
else
{
if(flag==false)
{
me.Play();
btnplayhold.Content="播£¤放¤?
";
flag=true;
return;
}
else
{
btnplayhold.Content="播£¤放¤?
";
musicplay();
return;
}
}
}
privatevoidbtnopen_Click(objectsender,RoutedEventArgse)
{
fbd.ShowDialog();
byte[]bs;
string[]str={"*.mp3","*.rmvb","*.jpg","*.avi","*.mp4","*.rm"};
foreach(stringsinstr)
{
if(fbd.SelectedPath=="")
{
System.Windows.Forms.MessageBox.Show("请?
选?
择?
正y确¨¡¤的Ì?
文?
件t夹D");
return;
}
strm=Directory.GetFiles(fbd.SelectedPath,s);
str8.Add(fbd.SelectedPath);
for(inti=0;i<=strm.Length-1;i++)
{
sb.Append(strm[i]);
sb.Append("\r\n");
listBox1.Items.Add(strm[i].Substring(strm[i].LastIndexOf("\\")+1));
}
}
FileStreamfs=newFileStream(AppDomain.CurrentDomain.BaseDirectory+"\\歌¨¨曲¨²列¢D表À¨ª.txt",FileMode.Append,FileAccess.Write,FileShare.ReadWrite);
bs=Encoding.Default.GetBytes(sb.ToString());
fs.Write(bs,0,bs.Length);
fs.Flush();
fs.Close();
if(listBox1.Items.Count==0)
{
System.Windows.Forms.MessageBox.Show("请?
选?
择?
正y确¨¡¤的Ì?
文?
件t夹D");
}
}
privatevoidbtnclose_Click(objectsender,RoutedEventArgse)
{
this.Close();
}
privatevoidlistBox1_MouseDoubleClick_1(objectsender,MouseButtonEventArgse)
{
musicplay();
}
privatevoidlistBox1_SelectionChanged(objectsender,SelectionChangedEventArgse)
{
flag=null;
}
privatevoidbtngo_Click_1(objectsender,RoutedEventArgse)
{
if(listBox1.SelectedIndex+1!
=0)
{
TimeSpants=newTimeSpan(0,0,3);
me.Position=me.Position.Add(ts);
}
}
privatevoidbtnback_Click_1(objectsender,RoutedEventArgse)
{
if(listBox1.SelectedIndex+1!
=0)
{
TimeSpants=newTimeSpan(0,0,3);
me.Position=me.Position-ts;
}
}
privatevoidslidvolume_ValueChanged(objectsender,RoutedPropertyChangedEventArgse)
{
me.ScrubbingEnabled=true;
me.Volume=slidvolume.Value;
}
privatevoidmusicplay()
{
Thread.Sleep(1000);
me.Close();
if(listBox1.SelectedItem.ToString()==null)
{
System.Windows.Forms.MessageBox.Show("请?
选?
择?
歌¨¨曲¨²");
return;
}
for(inti=0;i<=str8.Count-1;i++)
{
if(str8[i]!
="")
{
if(File.Exists(str8[i]+"\\"+listBox1.SelectedItem.ToString())==tru