用wpf做的音乐播放器.docx

上传人:b****8 文档编号:9127142 上传时间:2023-02-03 格式:DOCX 页数:23 大小:26.08KB
下载 相关 举报
用wpf做的音乐播放器.docx_第1页
第1页 / 共23页
用wpf做的音乐播放器.docx_第2页
第2页 / 共23页
用wpf做的音乐播放器.docx_第3页
第3页 / 共23页
用wpf做的音乐播放器.docx_第4页
第4页 / 共23页
用wpf做的音乐播放器.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

用wpf做的音乐播放器.docx

《用wpf做的音乐播放器.docx》由会员分享,可在线阅读,更多相关《用wpf做的音乐播放器.docx(23页珍藏版)》请在冰豆网上搜索。

用wpf做的音乐播放器.docx

用wpf做的音乐播放器

Wpf之音乐播放器

 

程序界面:

前台代码:

Class="音°?

乐¤?

播£¤放¤?

器¡Â.MainWindow"

xmlns="

xmlns:

x="

Title="音°?

乐¤?

播£¤放¤?

器¡Â"Height="361"Width="489"Loaded="Window_Loaded"Name="音°?

乐¤?

播£¤放¤?

器¡Â">

êo"Height="20"FontSize="10"Name="lable1"VerticalAlignment="Top"Foreground="Red">

媒?

体¬?

文?

件t"Click="MenuItem_Click">

除y单Ì£¤个?

媒?

体¬?

文?

件t"Click="MenuItem_Click_1">

空?

列¢D表À¨ª"Click="MenuItem_Click_2">

"Name="btnback"Click="btnback_Click_1"Foreground="Blue"BorderBrush="Blue"BorderThickness="5"/>

"Grid.Column="2"Grid.Row="1"Name="btngo"Click="btngo_Click_1"Foreground="Blue"BorderBrush="Blue"BorderThickness="5"/>

"Grid.Row="2"Grid.Column="1"Name="btnplayhold"Click="btnplayhold_Click"Foreground="Blue"BorderBrush="Blue"BorderThickness="5">

出?

"Grid.Column="2"Name="btnclose"Grid.Row="2"Click="btnclose_Click"Foreground="Blue"BorderBrush="Blue"BorderThickness="5">

一°?

曲¨²"Name="btnfor"Click="btnfor_Click"Grid.Row="0"Grid.Column="0"Foreground="Blue"BorderBrush="Blue"BorderThickness="5">

一°?

曲¨²"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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1